skip to Main Content

Timers and DeltaTime

By now, you should have noticed that in every Tick function there is a float parameter named DeltaTime. This parameter is equal to the seconds it took in order for the last frame to be completed. In this tutorial, I’m going to create a function which fires every X seconds using Timers

Creating a Timer

In UE4 we can set custom timers for specific events to fire. Say that you want a function named DoAPeriodicCheck to run every 10 seconds to happen, well that’s easy!

First of all, create a class which inherits from Actor (I named it TimerActor) and add the following property with the corresponding macro:

float LoopTime;

Moreover, we need a function that will execute every time that our custom timer will tick. I created the following function:

void DoAPeriodicCheck();

My header file is included in the following image:


Switch to your source file and type in the following function (this is the function that is going to be executed every LoopTime seconds):

Ok, now all we need to do is to tell the Actor in the BeginPlay function we want our timer to start. This can be done with the following code:

That’s all, now compile your code, create a Blueprint based on the class we created above and place it in your level. Then, set a value to the LoopTime, press play and wait for the DoAPeriodicCheck() to fire. Your output should be similar to the image below:


Avatar photo

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top