In this post I'm going to show you how to create latent Blueprint nodes that…
In this tutorial I’m going to show you how you can expose a C++ function to Blueprints. As you will see, the workflow is almost identical in the one I used for variable exposing. Let’s start!
Exposing a C++ function using the corresponding Macro
In order to expose a function to Blueprints, I created a class named MyActor and in the header file declared the function shown below (lines 23-24). Right before the declaration of the function I used the Macro UFUNCTION() which is used before functions. Just like variables, functions have their own macros with their own specifiers. For a full list of UFUNCTION() specifiers take a look at the official Unreal Engine documentation.
Warning: The Category specifier is mandatory, without it your code won’t be compiled.
The next step is to code the functionality for that function. To do so, I switch to the source file and type in the following code (lines 29-32):
Calling the C++ function from a Blueprint
I created a Blueprint which has the MyActor C++ class as parent class. If you write click anywhere on the graph and start typing DoSomething() you will eventually find the above method. In the following image, I called the DoSomething() method inside the BeginPlay: