Making Macros

A Macro is used to check if a player has enough energy to jump.

Choose your operating system:




On this page

Macros are essentially the same as collapsed graphs of nodes. They have an entry point and exit point designated by tunnel nodes. Each tunnel can have any number of execution or data pins which are visible on the macro node when used in other Blueprints and graphs.

Creating Macros

In this example, we will create a Macro that will be used to check if a player character has enough energy to jump or not. If they have enough energy to jump, we will remove some energy from the player and print their current value to the screen then allow them to jump. If they do not have enough energy, we will print to the screen that they are out of energy and not allow them to jump.

For this example, we are using the Blueprint Third Person Project with Starter Content enabled.

  1. Inside the Content/ThirdPersonBP/Blueprints folder, open the ThirdPersonCharacter Blueprint.

  2. Under the My Blueprint window, click the Add Macro button.


  3. A new Macro will be created, select it and press F2 to rename it to EnergyCheck .


  4. With the macro selected, in the Details panel, click the New buttons to create 1 Input and 2 Outputs.


    This will create Input/Output nodes on the Macro Node itself that can be used to pass data to/from the Macro.

  5. For the Input , in the text box enter the name BeginCheck and change the type to an Exec (Executable pin).

  6. For the Outputs , make them both Exec types and name one HasEnergy and the other NoEnergy .


    For the Input, we are using an Exec pin called BeginCheck to start the Macro. We will create script that checks if the player has enough energy to jump (and if so, will wire it to the HasEnergy pin). If they do not have enough energy, we will wire it to the NoEnergy pin. When we implement that Macro, the HasEnergy pin will be fed into the Jump command while the NoEnergy pin will not.

  7. Inside the My Blueprint window, click the Add Variable button.


  8. Name the variable Energy and change it to the Float type, click Compile from the Toolbar, then set its value to 100 .


    We now have a variable for the player's energy which has been initialized to 100.

  9. In the graph next to Inputs , hold the B key and Left-click to create a Branch node.

  10. While holding Ctrl drag Energy from the My Blueprint window into the graph and connect it to a > node, then connect it to the Branch .


    Here we are using a Branch to determine If Energy is > 0, and if so True is executed; if not False is executed.

  11. While holding Alt , drag in the Energy variable to add a Set node.

  12. Ctrl drag in Energy again and connect it to a - node, set to 10 and plug into the Set node.


    With this script we are saying if Energy is > 0, subtract 10 from the current Energy value.

  13. Right-click in the graph and add a Print String node, then connect the Energy to the In String pin.


    A Conversion node will be added which will convert the value of Energy into a string that is printed to the screen, displaying its value.

  14. Off the False pin of the Branch , add a Print String and enter the text Out of Energy! in the box.

  15. Connect both Print String nodes to the HasEnergy and NoEnergy pins.


    The Macro is now set up to check (and if applicable, subtract from) the Energy variable and spit out if the player has enough energy or not which will be used to determine if the player can jump or now. Now we need to implement the Macro after pressing the "Jump" key before Jump is executed.

  16. On the EventGraph , drag off the Pressed pin of InputAction Jump node and search for EnergyCheck .


    You should see that the Macro we created is listed under Utilities and has the Macro icon next to its name.

  17. When the Macro is added, the Jump script should look similar to below.


  18. Click the Compile and Save buttons, then close the Blueprint.

  19. Click the Play button from the Main Toolbar to play in the Editor.

    When you press the Spacebar to jump, in the upper left corner of the screen the value of Energy is printed to the screen. When Energy is 0, you should no longer be able to jump.

    This is basic example of using a Macro to execute and consolidate script into a single node, improving the readability of our Event Graph and main character script. Additionally, you could call this Macro in other instances - say you have some other action that reduces the player's energy and you want to check if they have enough energy to perform the action (attacking for example). You could run this Macro to check if the player has enough energy to Attack after pressing your Attack key then execute an attack off the HasEnergy exec pin.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey