UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::EventLoop::TTimerManager< Traits > Class Template Referencefinal

#include <EventLoopTimer.h>

+ Inheritance diagram for UE::EventLoop::TTimerManager< Traits >:

Public Types

using FStorageType = TManagedStorage< FTimerData, typename Traits::FStorageTraits >
 
using FTimerHandle = typename FStorageType::FExternalHandle
 
using FInternalHandle = typename FStorageType::FInternalHandle
 
using FInternalHandleArryType = typename FStorageType::FInternalHandleArryType
 

Public Member Functions

void Init ()
 
void Tick (FTimespan DeltaTime)
 
bool GetNextTimeout (FTimespan &OutTimeout) const
 
uint32 GetNumTimers () const
 
FTimerHandle SetTimer (FTimerCallback &&Callback, FTimespan InRate, bool InbRepeat=false, TOptional< FTimespan > InFirstDelay=TOptional< FTimespan >())
 
void ClearTimer (FTimerHandle &InHandle, FOnTimerCleared &&OnTimerCleared=FOnTimerCleared())
 
bool HasPendingRepeatTimer () const
 

Additional Inherited Members

- Protected Member Functions inherited from FNoncopyable
 FNoncopyable ()
 
 ~FNoncopyable ()
 

Detailed Description

template<typename Traits = FTimerManagerDefaultTraits>
class UE::EventLoop::TTimerManager< Traits >

Timer manager for posting timers to an event loop.

The event loop timer manager provides the guarantee that its timers will never fire early while only progressing its view of time based on the delta passed to its Tick method. To provide this guarantee, timers may fire later than requested which is by design.

Adding and removing timers are thread-safe, however the timer callback and clear callbacks will both be called from within the Tick method, which may be a different thread. It is up to the user to handle thread safety within their callbacks.

Member Typedef Documentation

◆ FInternalHandle

template<typename Traits = FTimerManagerDefaultTraits>
using UE::EventLoop::TTimerManager< Traits >::FInternalHandle = typename FStorageType::FInternalHandle

◆ FInternalHandleArryType

template<typename Traits = FTimerManagerDefaultTraits>
using UE::EventLoop::TTimerManager< Traits >::FInternalHandleArryType = typename FStorageType::FInternalHandleArryType

◆ FStorageType

template<typename Traits = FTimerManagerDefaultTraits>
using UE::EventLoop::TTimerManager< Traits >::FStorageType = TManagedStorage<FTimerData, typename Traits::FStorageTraits>

◆ FTimerHandle

template<typename Traits = FTimerManagerDefaultTraits>
using UE::EventLoop::TTimerManager< Traits >::FTimerHandle = typename FStorageType::FExternalHandle

Member Function Documentation

◆ ClearTimer()

template<typename Traits = FTimerManagerDefaultTraits>
void UE::EventLoop::TTimerManager< Traits >::ClearTimer ( FTimerHandle InHandle,
FOnTimerCleared &&  OnTimerCleared = FOnTimerCleared() 
)
inline

Clears a previously set timer.

Thread safe.

Parameters
InHandleThe handle of the timer to clear.
OnTimerClearedCallback to be fired when the timer has been removed. The callback will be fired within the Tick method which may be a different thread from which the timer clear was requested.

◆ GetNextTimeout()

template<typename Traits = FTimerManagerDefaultTraits>
bool UE::EventLoop::TTimerManager< Traits >::GetNextTimeout ( FTimespan OutTimeout) const
inline

Retrieve the remaining time since the last call to Tick before the next timer will fire.

NOT thread safe.

Parameters
OutTimeoutTime amount of time relative to TimerManagers' internal time until the next valid timer will run.
Returns
true if a valid timer is currently set.

◆ GetNumTimers()

template<typename Traits = FTimerManagerDefaultTraits>
uint32 UE::EventLoop::TTimerManager< Traits >::GetNumTimers ( ) const
inline

Returns the total number of timers. Includes active timers and timers waiting to be rescheduled.

NOT thread safe.

Returns
the total number of timers.

◆ HasPendingRepeatTimer()

template<typename Traits = FTimerManagerDefaultTraits>
bool UE::EventLoop::TTimerManager< Traits >::HasPendingRepeatTimer ( ) const
inline

Returns whether any timers are waiting to be rescheduled.

NOT thread safe.

Returns
true if a valid timer is waiting to be rescheduled.

◆ Init()

template<typename Traits = FTimerManagerDefaultTraits>
void UE::EventLoop::TTimerManager< Traits >::Init ( )
inline

Initialize the timer manager and its storage.

NOT thread safe.

◆ SetTimer()

template<typename Traits = FTimerManagerDefaultTraits>
FTimerHandle UE::EventLoop::TTimerManager< Traits >::SetTimer ( FTimerCallback &&  Callback,
FTimespan  InRate,
bool  InbRepeat = false,
TOptional< FTimespan InFirstDelay = TOptional<FTimespan>() 
)
inline

Set a new timer. The timer callback will be triggered from within the call to Tick, which may occur on a different thread from the one which set the timer.

Thread safe.

Parameters
CallbackCallback to call when timer fires.
InRateThe amount of time between set and firing.
InbRepeattrue to keep firing at Rate intervals, false to fire only once.
InFirstDelayThe time for the first iteration of a looping timer.
Returns
handle to the registered timer.

◆ Tick()

template<typename Traits >
void UE::EventLoop::TTimerManager< Traits >::Tick ( FTimespan  DeltaTime)

Accumulate the timer managers elapsed time and fire timers which have elapsed.

NOT thread safe.

Parameters
DeltaTimeThe amount of time which has elapsed since the last call to Tick.

The documentation for this class was generated from the following file: