I was working on a blueprint driven conversation system and need a node that would wait for the player to pick a conversation option before resuming the blueprint execution. When I added it I noticed that when the blueprint was resumed by player input it would immediately execute the node again and start waiting for player input once more. The only difference between this and other latent functions I’ve seen was that it was not static and that it had no parameters other than FLatentActionInfo.
Here is a reduced example that seems to have the same behavior:
/**
* A test for two latent methods.
*/
UCLASS()
class LATENTTEST_API ALatentTestGameMode : public AGameMode
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, meta=(Latent, LatentInfo="LatentInfo"), Category="Test")
void LatentFunctionNoArgs(FLatentActionInfo LatentInfo);
UFUNCTION(BlueprintCallable, meta=(Latent, LatentInfo="LatentInfo"), Category="Test")
void LatentFunctionWithArgs(float Dummy, FLatentActionInfo LatentInfo);
};
The implementation does nothing more than call Delay.
void ALatentTestGameMode::LatentFunctionNoArgs(FLatentActionInfo LatentInfo)
{
UKismetSystemLibrary::Delay(this, 1.0f, LatentInfo);
}
void ALatentTestGameMode::LatentFunctionWithArgs(float Dummy, FLatentActionInfo LatentInfo)
{
UKismetSystemLibrary::Delay(this, 1.0f, LatentInfo);
}
Next is an instance of a game mode blueprint created with ALatentTestGameMode as its base. Only the BeginPlay event is wired up.
This blueprint can now be used as the override game mode in a newly created level.
When the exec is wired up to “Latent Function No Args” as in the screenshot, the breakpoint is never hit and the text is never printed. Putting the breakpoint on the latent node itself hits the breakpoint every one second.
On the other hand, when the exec is wired up to “Latent Function with Args” the blueprint runs as expected with the breakpoint being hit and the string printed after one second.