跟Delegate一起用
FTimerDelegate TimerCallback;
TimerCallback.BindLambda([]
{
// callback;
});
FTimerHandle Handle;
GetWorld()->GetTimerManager().SetTimer(Handle, TimerCallback, 5.0f, false);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
UI回调事件
SNew(SButton).OnClicked_Lambda([&]()
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!"));
return FReply::Handled();
})
- 1
- 2
- 3
- 4
- 5
跨线程执行
FFunctionGraphTask::CreateAndDispatchWhenReady([=]()
{
// game thread code
}
, TStatId(), nullptr, ENamedThreads::GameThread);
- 1
- 2
- 3
- 4
- 5
- 6
批量执行
void USkeletalMeshComponent::SetAllBodiesBelowSimulatePhysics( const FName& InBoneName, bool bNewSimulate, bool bIncludeSelf )
{
int32 NumBodiesFound = ForEachBodyBelow(InBoneName, bIncludeSelf, /*bSkipCustomPhysicsType=*/ false, [bNewSimulate](FBodyInstance* BI)
{
BI->SetInstanceSimulatePhysics(bNewSimulate);
});
...
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
以上部分转自 http://blog.csdn.net/xoyojank/article/details/52859518
补充知识:Lambda简介 http://blog.csdn.net/remote_roamer/article/details/52925477
Lambda 表达式有何用处?如何使用? https://www.zhihu.com/question/20125256