Sitemap
Brian Stong

Brian Stong

Hi! I'm a Unity & Unreal game developer focused on crafting fun interactive adventures & sharing what I learn along the way.

Delay Function in Unreal Engine C++

2 min readOct 31, 2025

So in my Lander game I was trying to find a way to delay execution of a function to restart the level after 3 seconds when the player’s ship gets destroyed, time for the player to see their ship go down in a blaze of glory whilst reflecting on what had happened and how to improve for the next run. In Unity I’d have used a Coroutine, but in Unreal, here’s what I found:

LanderGameMode.cpp listens for the ShipDestroyed event from the Ship class and calls this HandleShipDestroyed() function when triggered:

Press enter or click to view image in full size
LanderGameMode.cpp

On Line 135 we use GetWorld()->GetTimerManager().SetTimer(); This function creates a timer that calls another function after a specified delay. The first parameter, LevelLoadTimer is an FTimerHandle used for this timer, declared in LanderGameMode.h:

Press enter or click to view image in full size
LanderGameMode.h

Taking a look at the rest of the parameters in SetTimer():

Press enter or click to view image in full size

We can see that this (LanderGameMode.cpp) is the class that will call a function, &ALanderGameMode::RestartCurrentLevel, after 3.0 seconds, and false (it’s not going to fire in intervals, it’ll just fire one time).

Get Brian Stong’s stories in your inbox

Join Medium for free to get updates from this writer.

And here we have RestartCurrentLevel() that’ll actually restart the level after the 3 second delay:

Press enter or click to view image in full size
We just get the CurrentLevelName and open up that level to restart.

And here’s what we got:

Press enter or click to view image in full size
🎃

I’ll change the automatic restart to UI Restart/Quit Buttons later, but for now delay functions in Unreal C++!

--

--

Brian Stong
Brian Stong

Written by Brian Stong

Hi! I'm a Unity & Unreal game developer focused on crafting fun interactive adventures & sharing what I learn along the way.