Spawn order when Play button is pressed

So I ran into an initially strange bug, where a reference to my game mode instance was not valid despite the game mode being created properly.
I realized that this was most likely due to the order in which all the objects of my unreal world are created. So I was wondering what exactly is the spawning order in which the objects that are part of my unreal level are spawned? Is it true, that anything that I pull into my level (in my case e.g. a simple fighter unit) has its BeginPlay() function called before my game mode instance has its BeginPlay() function called?

Thank you:)

I’m pretty sure the game mode is running before begin play is called.

1 Like

Thank you and sorry for the late response, almost forgot about the post due to the post approval thing.
You are right and I found a list of the actual order in which things are initialized when you click play. Actually, the order differs for editor play and “packaged” play. So never assume you can reference something in your event begin play function unless you know what you are doing. Ran into the issue of reference not being valid within the beginPlay function.
See Game Flow Overview | Unreal Engine 4.27 Documentation
and some other post in this forum which summarized it nicely which I unfortunately cannot find at the moment.

tl;dr:
Take good care what you are referencing in your BeginPlay function and make sure the reference really is valid the moment that beginplay function is called. It is better to refer to other objects outside of the beginplay function.

1 Like