Hello again. Today I will be walking you through my process of how to create an increasing timer in Unreal Engine 4. To my surprise, there doesn’t seem to be any pre-made function that can do this for us. This means we will have to rely on math to solve our problem here. I learned how to create this function from resources online.
First off, we want to go into the game mode blueprint. In my case it is FirstPersonGameMode. Within the blueprint, we need to create 2 variables that are both type Integer. One of these variables will be the seconds of the timer, and the other will be the minute, you can name them accordingly. Connect a delay node to the Event Tick node, and the delay time to 1 second. After the delay, simply set the Seconds variable and increment it by 1. As you can see, after 1 second, our seconds variable will be incremented by 1.
From there we need to create a branch node and evaluate if the seconds variable is higher than 60. As you can guess, if the seconds are higher than 60, we increment the minutes variable by 1. If the seconds are higher than 60 and we increment the minute variable, we must then set the seconds variable to 0. That is actually it! If you want to check it it’ working, you can add a print string node after we set the seconds or minute and see it update in your game.
The second part of this process is to display this on the UI. First we need to create a widget blueprint. From there we can drag 2 text blocks onto the widget display, you can place them as you like but keep in mind one will be the seconds and the other will be the minutes. With whatever text block you want to be minutes, select it and make sure you check the “is variable” box under the details section. From there, under the context section of the details tab, hit create binding. In the binding, we will cast it to our game mode, and from there we get minutes, convert it into a string and connect the value to the return node. We will do the same thing for the other text block (seconds) but instead of getting minutes, we will get seconds.
All we have to do from here is create and add it to the viewport. I chose to do this in my FirstPersonGameMode blueprint as well.
Thanks for reading.
Saarim