Creating Latent Functions for Blueprints in C++
Updated: 2 days ago
While working on an AWS Blueprint library, I came across the need to expose some Latent Actions to blueprint.
A Latent Action is a node that can be called in a blueprint that will return at some point in the future. The best example is the Delay node.
In this example, LedgeGrabEnabled will not be set to true until 1 sec has passed.
All the network calls I was making would return at some point in the future, so it made sense to implement a latent action. Then the Blueprint user can take action with the result of the call. Latent functions are a perfect fit for async operations like network calls.
There are several parts of implementing a latent action:
First, define the latent function in your blueprint library. e.g.
Next, implement the function, making sure to utilize FLatentActionManager.
As you can see, the primary purpose of this is to add your custom FPendingLatentAction(s) to LatentActionManager. (FAWSDelayAction is the custom latent action for my applciation).
The job of the LatentActionManager is to tick all these pending actions every frame. If the action has completed, then it should use the other information in the latent action to notify the user and call whatever ever they specified. This is typically don by calling FinishAndTriggerIf within the action's UpdateOperation.
Typically, you override your own custom action.
As an example, here is the Delay action from source:
Using latent actions is a great way to let the blueprint user do something with the result of your async operation.