Flayer Promises
Return an FFlayerPromise when a Flayer handler starts work that takes multiple frames. The game thread remains available while the operation runs, and the SDK replies when the promise completes.
Managed promises are cancelled when their call is cancelled, the connection closes, the world is cleaned up, or the SDK shuts down. The default managed timeout and incoming call deadline are 30 seconds.
Promise utility helpers
The promise utilities cover common asynchronous patterns:
DelayedPromisecompletes after a delay.ConditionalPromisechecks a condition at an interval.TickingPromiseinvokes a callback at an interval until it reports completion.- The corresponding
WithResulthelpers let a callback produce its result when it completes.
A promise helper takes a world context, an eventual result, and timeout options. A zero timeout uses the default managed timeout.
#include "Utils/FlayerPromiseUtils.h"
FFlayerPromise WaitBriefly(float DelaySeconds)
{
FDynamicParams Result{FDynamicParam(true)};
return UFlayerPromiseUtils::DelayedPromise(this, DelaySeconds, Result);
}For a promise-returning handler, declare the eventual result type in its function metadata:
FFlayerFunctionMeta Meta;
Meta.PacketName = TEXT("wait_briefly");
Meta.Description = TEXT("Waits for a short delay and returns true");
Meta.HintKey = TEXT(".*");
Meta.PromiseReturnType = EParamType::Bool;
RegisterCodeFunction(TEXT("WaitBriefly"), Meta);Use EParamType::Null when the promise returns no value. Other result types require exactly one value of the declared type.
Complete a managed promise directly
A library can create a managed promise, attach completion or cancellation callbacks, and complete it after its operation finishes:
FFlayerPromise Promise = CreateFlayerPromise(TEXT("load_level"));
AddOnCompletedFlayerPromise(
Promise,
FOnPromiseCompleted::FDelegate::CreateLambda(
[](const FDynamicParams& Result)
{
UE_LOG(LogTemp, Log, TEXT("Level load finished"));
}
)
);
// Later, on the game thread:
CompleteFlayerPromise(Promise, FDynamicParams{FDynamicParam(true)});Use AddOnCanceledFlayerPromise to clean up game-side work when the call ends before the promise completes. Managed promise callbacks and game object access should run on the game thread.
Tick or wait on game state
Use a ticking helper when completion depends on state that changes during play. A tick delegate returns true to finish. Use a weak reference for objects that may be destroyed while the promise is pending.
TWeakObjectPtr<AActor> WeakTarget(Target);
FStandardPromiseTickAndResultDelegate OnTick =
FStandardPromiseTickAndResultDelegate::CreateLambda(
[WeakTarget](float DeltaTime, FDynamicParams& Result)
{
if (!WeakTarget.IsValid())
{
Result = FDynamicParams{FDynamicParam(false)};
return true;
}
if (!WeakTarget->IsHidden())
{
return false;
}
Result = FDynamicParams{FDynamicParam(true)};
return true;
}
);
return UFlayerPromiseUtils::TickingPromiseWithResult(
this,
OnTick,
FDynamicParams{FDynamicParam(false)},
10.0f,
0.1f
);The helper checks the delegate at the configured interval. The operation in the example returns true when the target becomes hidden and false if the target is destroyed. If the helper deadline expires, the managed promise reports a timeout error.
For a longer example that uses promises with Unreal navigation, see Simple Navigation.