Do not use level blueprint (partially because of load order trouble, and that you cannot reference actors that are not loaded yet).
Instead make an actor that does your code, and place that actor in level.
Load order is kind of messed up (but makes perfect sense when you think about it).
And for more global code use game mode or something similar.
Generally Unreal can only spawn actors that have all components loaded and constructed.
So if you have actor with multiple components it needs to construct components first, then actor. This usually means you are not guaranteed to have proper owner reference when you try get it from something that was spawned first.
It is even worse, because it probably may differ depending on platform, if game is run in editor or standalone etc.
So instead of fixing load order bugs later, it is better to create code that does not care about load order.
You should use print to log or visual logger, and print on begin play which actor has begin. This will sshow you load order, but remember it is not guaranteed.
So my problem with load order:
- i had multiple actors in level that had some information
- they all had widgets in 3d that display it
- also same widgets were in panel ans umg
I wanted both widgets to have same code (ie. custom umg widgets that i placed either on actor or in hud).
Problem was widgets in 3d spawned first, then their owning actors, then was game mode, then same widgets but in hud.
So widget code was not guaranteed to spawn after actors.
I solved this whole mess by:
- making disspatcher in game mode caled “real begin play”
- each widget tried find owning actor and cast to its type to hook and read info.
- if that hooking code failed, it hooked to dispatcher in game mode instead.
- when that “real begin play” was triggered widget tired hook to actor again, this time with actor constructed.
Then game mode did its all starting up stuff. then i added that dreaded 0.2 sec delay, and triggered dispatcher.
So you could do your code in level blueprint. make al actors hook to dispatcher “real begin play” in game mode. then level blueprint when its done triggers that dispatcher, and all actors execute code.
Yes whole load order in unreal is mess, but i do not think they could do it in different way.