ue4 setTimer定时器传参数

新建一个c++类AActor

方式一

.h文件

void timer(int32 a);
void Calltimer();

.cpp文件

void AActor::Calltimer()
{
    int32 a = 3;
    FTimerHandle UniqueHandle;
    FTimerDelegate RespawnDelegate = FTimerDelegate::CreateUObject(this, &AActor::timer, a);
    GetWorldTimerManager().SetTimer(UniqueHandle, RespawnDelegate, 3.0f, false);

}
void AActor::timer(int32 a)
{
	
}

方式二

.h文件

void Calltimer();

UFUNCTION()
void timer(int32 a);

.cpp文件

void AAdapterActor::Calltimer()
{
    FTimerHandle TimerHandle;
    FTimerDelegate TimerDel;
    int32 a = 1;
    //Binding the function with specific values
    TimerDel.BindUFunction(this, FName(TEXT("timer")), a);
    //Calling MyUsefulFunction after 2 seconds without looping
    GetWorldTimerManager().SetTimer(TimerHandle, TimerDel, 2.0f, false);
}

void AAdapterActor::timer(int32 a)
{
	
}

 

你可能感兴趣的:(ue4)