栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

虚幻引擎在C++中实现蓝图中的Delay功能

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

虚幻引擎在C++中实现蓝图中的Delay功能

网上有人推荐说使用 FPlatformProcess::Sleep(1.0f);

其实使用这种方法会导致整个程序被延迟,并不是我们想要的。

有两种方法模拟延迟,实际上彼此没有区别。

1、在BindLambda中使用FTimerDelegate
FTimerDelegate TimerDelegate;
TimerDelegate.BindLambda([&]
{
	UE_LOG(LogTemp, Warning, TEXT("This text will appear in the console 3 seconds after execution"))
});

FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 3, false);

2. 只使用FTimerHandle
FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, [&]()
{
	UE_LOG(LogTemp, Warning, TEXT("This text will appear in the console 3 seconds after execution"))
}, 3, false);

第二种方法是使用延迟来执行另一个函数。下面的示例使用动态绑定,但您也可以通过BindUFunction进行绑定。

1、如果没有输入参数
FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &UObject::MethodWithDelay, 3, false);

2、如果有输入参数
int32 ParameterToPass = 100; // You can use any supported variable type

FTimerHandle TimerHandle;
FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &UObject::MethodWithDelay, ParameterToPass);
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 3, false);

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/976563.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号