In this lesson, you will learn how to use the Timer Manager to schedule gameplay actions precisely, replacing expensive Tick logic with efficient, time-based events.
Why Avoid Tick?
Up until now, you have likely relied on the Tick function to check if a cooldown has finished or if an ability is ready. However, Tick runs every single frame—even when nothing is happening. If you have 50 actors all checking cooldowns every frame, you are wasting precious CPU performance. Instead, we use the Timer Manager, which allows an Actor to "set an alarm" and then go back to sleep until the timer fires.
Setting Up a Cooldown
The Timer Manager acts as a central registry for all delayed events in your game. To implement a cooldown, you define a function that performs the action (like resetting an ability) and then ask the Timer Manager to execute it after a specific delay.
// In your Actor's header
FTimerHandle CooldownTimerHandle;
void ResetAbility();
// In your Actor's .cpp (when triggering the ability)
float CooldownDuration = 5.0f;
GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &AMyActor::ResetAbility, CooldownDuration, false);
How It Works
- The Timer Handle: Think of this as a unique ID tag for the alarm you just set. It allows you to pause, clear, or check the status of that specific timer later.
- The Delegate: You point the timer to a specific function (
&AMyActor::ResetAbility). - The Delay: You provide the float value for how many seconds to wait.
- Looping: The final boolean parameter determines if the timer should repeat. By setting it to
false, the logic runs exactly once and then finishes, saving your game's performance.
Because this system is handled by the engine's internal manager, it is significantly more accurate and performant than checking time manually inside Tick. You can use these timers to manage everything from potion effects and weapon reload times to complex AI behavior sequences.
Key Takeaway: Replace frame-by-frame Tick checks with Timer Manager handles to schedule precise gameplay logic while maintaining optimal engine performance.