Using Macro Libraries

Choose your OS:

A Macro Library is a container that holds a collection of Macros or self-contained graphs that can be placed as nodes in other Blueprints. These can be time-savers as they can store commonly used sequences of nodes complete with inputs and outputs for both execution and data transfer.

Creating a Macro Library

In this example we create a Macro Library consisting of two macros, one of which is used to add to a "Health" variable and the other is used to adjust the size of an Actor that is specified.

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

  1. Right-click in an empty space in the Content Browser then in the context menu under Blueprints, select Blueprint Macro Library .

    CreateLib1.png

  2. In the Pick Parent Class window that appears, select your Parent Class (for this example, select Actor).

    CreateLib2.png

  3. Enter a name for your Macro Library, then Double-click on it to open it up.

    CreateLib3.png

    This will display the Blueprint Macro interface.

    CreateLib4.png

  4. In the MyBluprint window in the upper-right, rename the default macro to ScaleUp by pressing F2 on it.

  5. In the Details panel for the ScaleUp macro, add the Inputs and Outputs shown below.

    CreateLib5.png

    Above we have created two inputs, one called In set to the Exec type and the other called InActor set to the Actor type. The output added is called Out and is set to the Exec type. We will use these to determine the Actor that we want to affect through this macro.

  6. In the graph for the ScaleUp macro, recreate the node network indicated below.

    CreateLib6.png

    Above, when this macro is called it will get whatever Actor is provided as the InActor and get its current scale to which it will multiply it by 1.25 before setting it as the new scale 3D for the Target (which is the Actor specified as the InActor.) We can now use this macro with any Actor and affect their scale through the use of this macro.

  7. Add another macro from the MyBlueprint window called AddHealth.

  8. In the Details panel for AddHealth, add the Inputs and Outputs shown below.

    CreateLib7.png

    Above we are taking in a float value called GetHealth which we will add to before we pass it through to the SetHealth output node.

  9. In the graph for the AddHealth macro, recreate the node network indicated below.

    CreateLib8.png

    Above we are adding 50 to whatever float value is provided as the GetHealth value before outputting the resulting value to SetHealth.

  10. Save and close the Blueprint Macro Library.

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

  12. In the MyBlueprint window, add a Float variable to represent Health (we left the default value to 0).

    CreateLib9.png

  13. In the Event Graph, recreate the node network indicated below.

    CreateLib10.png

    Above we are calling the AddHealth macro whenever Q is pressed which takes in the Health variable (performs the macro script of increasing it) and updates it with the out pin SetHealth before printing it to the screen. We then use E and check if Health is greater than 100 before we allow the ScaleUp macro to be called on the Actor Self which is the ThirdPersonCharacter.

  14. Compile and Play in the editor.

    To better see the text printed to the screen, watch the video above in fullscreen.

    In the video above, we included the Blueprint Script from step 13 so that we can see when the script is being fired. When we press E to attempt to call the ScaleUp macro, we first check the Health value which by default we set to 0. We then press Q to call the AddHealth macro to increase the Health variable each time it is pressed by 50. After a few presses, we then try the ScaleUp macro again and now we can see that it gets the call because our Health has been increased and is greater than 100.

    These macros can be called from any other Blueprints provided the inputs for Health and the Target Actor are supplied.

Tags