OpenLevel from game instance init not working

Hi,

I’m trying to load a specific level from the game instance when the game starts, but only in certain circumstances. I currently do so by calling OpenLevel (after checking for the circumstances) in the GameInstance event Init, which works in the editor.
However, in a packaged project, the OpenLevel still gets called but instead the game still loads the Game Default Map.

I’m guessing this happens as the OpenLevel call happens without being able to open a level yet cause of the execution order. It’s crucial though that the initial code runs from the game instance init.
But now I’m left wondering how I can force the correct map to open.

My current solution is to use a 1 frame delay before calling OpenLevel, but I’m not sure how consistent this is as I’ve had trouble with it in the past.

Is there some sort of callback when the game is ready to load a level? I’m willing to use C++ if needed.

Thanks in advance

The execution flow does indeed differ between PIE and standalone. One solution is to create an empty level as your default level who’s only purpose is to run the map selection code through the GameMode or level blueprint. This ensures that the game is sufficiently ready.

We were slightly skeptical at first about having our game flow depend on our game default map, as we read somewhere that an end-user can force load a certain map in a build through command line.
And skipping any part of our logic might break the rest of the application.

However, upon looking further into it, it seems this option can be enabled/disabled so I guess we disable it and then we can use your solution.

Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.