跟Delegate一起用
FTimerDelegate TimerCallback;
TimerCallback.BindLambda([]
{
// callback;
});
FTimerHandle Handle;
GetWorld()->GetTimerManager().SetTimer(Handle, TimerCallback, 5.0f, false);
UI回调事件
SNew(SButton).OnClicked_Lambda([&]()
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!"));
return FReply::Handled();
})
跨线程执行
FFunctionGraphTask::CreateAndDispatchWhenReady([=]()
{
// game thread code
}
, TStatId(), nullptr, ENamedThreads::GameThread)
批量执行
void USkeletalMeshComponent::SetAllBodiesBelowSimulatePhysics( const FName& InBoneName, bool bNewSimulate, bool bIncludeSelf )
{
int32 NumBodiesFound = ForEachBodyBelow(InBoneName, bIncludeSelf, /*bSkipCustomPhysicsType=*/ false, [bNewSimulate](FBodyInstance* BI)
{
BI->SetInstanceSimulatePhysics(bNewSimulate);
});
...
}