How to delay game start until a condition is met?

By the time the first world (main menu) is loaded, a game instance subsystem should have completed some async work, for example loaded assets or pre-compiled shaders. During this time, the “game” should not start and user input should be disabled (maybe with a loading screen). However, the game thread should not be blocked and the application should remain responsive (e.g. exit, window resizing).

How can we delay the engine until some async callback using C++?
How can this be done not only on startup but whenever background work is a pre-requisite to continuing?

Hey,

You can’t really pause or delay the engine itself, but you can hold the game flow using these delegates:

FCoreUObjectDelegates::PreLoadMapWithContext
FCoreUObjectDelegates::PostLoadMapWithWorld

You can use PreLoadMap to show a loading screen. When PostLoadMapWithWorld fires, the map is already loaded, but you don’t have to start gameplay yet.

From there, you can use Tick or a timer to check whether your async work has finished. While it hasn’t, keep the loading screen and input disabled. As soon as the async load completes, just remove the loading screen and let the game start.

Hope that helps!

1 Like