keywords: UE4 Timer

Register Timer

1st way:

GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &AMyActor::TestFun, 0.5f, false);

2nd way:

FTimerDelegate TimerDel;
TimerDel.BindUFunction(this, FName("TestFun"));
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, 5.f, false);

In 2nd way, TestFun must be marked as UFUNCTION.

Clean Timer
// Ensure the fuze timer is cleared by using the timer handle

// Alternatively you can clear ALL timers that belong to this (Actor) instance.
How to pass parameters when using GetWorldTimerManager().SetTimer()

Callback Function:

void MyUsefulFunction(int32 x, float y);


FTimerDelegate TimerDel;
FTimerHandle TimerHandle;


int32 MyInt = 10;
float MyFloat = 20.f;

//Binding the function with specific values
TimerDel.BindUFunction(this, FName("MyUsefulFunction"), MyInt, MyFloat);
//Calling MyUsefulFunction after 5 seconds without looping
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, 5.f, false);



Using C++ Timers in Unreal Engine 4