Using Timers in Blueprints

A How To Guide for using timers in Blueprints.

This page covers how to use Timers for gameplay purposes in Blueprints and the nodes associated with Timers.

Creating and Clearing Timers

The steps below will show you how you can create/set a Timer in Blueprints.

For this example, we are using the Blueprint Third Person Template and will be causing fire damage to the player over time.

Inside your project, open the ThirdPersonCharacter Blueprint.

Right-click in the graph and add two Custom Events called PlayerInFire and PlayerNotInFire.

In the MyBlueprint window, add a new Function called FireDamage.

This Function will be called over time by the Timer and will apply the damage.

Drag off the PlayerInFire Event and add the Set Timer by Function Name node.

Drag off the PlayerNotInFire Event and add the Clear Timer by Handle node.

For Set Timer by Function Name, set the Function Name to FireDamage.

On the Set Timer, set the Time to 0.75 and check the Looping box.

Connect the Return Value pin of the Set Timer by Function Name node to the Handle pin of the Clear Timer by Handle node.

The Time entered is the interval in which the Function Name Function will be called (every 0.75 seconds).

Create a new Integer variable called PlayerHealth, click Compile, then set the Default Value to 100.

Inside the FireDamage Function, while holding down the Alt key, drag the PlayerHealth variable into the graph.

Hold down Control and drag in the PlayerHealth variable as well.

Drag off the PlayerHealth variable and add an Integer - Integer node, then off the 0 pin, add a Random Integer in Range node.

We used a Random Integer in Range node with Min (1) and Max (4) values, however you can enter a damage value if you wish.

Off the Set node, add a Print String then Control drag in PlayerHealth and connect it to the Print String.

We are not displaying Health Bars in this example; however this will show us that the Health Value is indeed decreasing.

Open the Blueprint_Effect_Fire Blueprint located in the Content/StarterContent/Blueprints folder.

Click the Add Component button and add a Box shape and call it Trigger.

When the player enters/exits this Trigger, we will call the Events in the ThirdPersonCharacter Blueprint.

Locate the My Blueprint tab and Right-click on the Trigger and add the OnComponentBegin and OnComponentEnd Overlap Events.

Drag off the Other Actor pin of each and add the Cast To ThirdPersonCharacter node.

Drag off the As Third Person Character C pin and (for the Begin node) add PlayerInFire and (for the End node) PlayerIsNotInFire Events.

Compile and Save, then close the Blueprint.

In the Content Browser, drag the Blueprint_Effect_Fire Blueprint into the level.

When you click the Play button to play in the editor, enter the fire and you should see you start to take damage.

This is an example of how you could use timers to create a damage-over-time effect; however you could use timers to represent other things such as a power-up that lasts for X seconds which allows the player to be invincible or have some other ability.

Additional Timer Related Nodes

While the Set Timer by Function Name and Clear Timer by Handle nodes are used to start/stop a Timer, the nodes below may also be of use based on your needs.

Get Timer Elapsed and Get Timer Remaining

The Get Timer Elapsed by Handle and Get Timer Remaining by Handle nodes will get the amount of time that has elapsed since starting or get the amount of time remaining for the specified Timer (indicated by the Handle). It returns the value as a Float and can be used for several different purposes, for example, changing an effect over time or providing a message when an effect is about to expire.

Pause Timer and Un Pause Timer

As the names suggest, the Pause Timer by Handle pauses the timer at its current time whereas the Clear Timer by Handle stops it entirely and resets it. The Unpause Timer by Handle node can be used to resume a paused timer and pick up where it left off. One example use case would be if a player has an effect applied to them that runs on a timer and they enter a menu or inventory screen for example and you want to pause the effect and resume it when they return to gameplay.

Timer Exists, Is Timer Active and Is Timer Paused

The Does Timer Exist by Handle, Is Timer Active by Handle, and Is Timer Paused by Handle nodes all return a True or False value and can be used to determine if a Timer exists, if a Timer is currently active or if a Timer is currently paused respectively.

Set Timer by Event

The Set Timer by Event node functions similar to the Set Timer by Function Name node except instead of specifying a Function Name, you can connect a Custom Event which will be fired. You can set this to looping as well, just as you could with the Set Timer by Function Name node.