FTimerManager class in Unreal Engine

Published on

A class to globally manage timers. It may be used anytime there's a need to work with a time.

Platforma

Set time interval

//.h file
FTimerHandle FireRateTimerHandle;
float FireRate = 5.f; // initialDelay (+ frequency when bLoop = true)
void TriggerFire();

// .cpp file
<a href="/unreal-engine/forward-declaration">#include "TimerManager.h"</a>
AExample::BeginPlay()
{
    Super::BeginPlay();
    bool bLoop = true; // run in a loop (FireRate specifies frequency)
    GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &AExample::TriggerFire, FireRate, bLoop);
}
AExample::TriggerFire()
{
    if(bCanFire) Fire();
}

Timer with a callback function and input parameter

FTimerDelegate allows to create an object that can bind a function, see the code below:

FTimerDelegate InputDelegate = FTimerDelegate::CreateUObject(PlayerController, &AExample::TriggerSomething, Value);
GetWorldTimerManager().SetTimer(TimerHandleVariable, InputDelegate, StartDelayTime, bLoop);
Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us