order of BeingPlay in blueprints: Level vs. Actors

is there a way to run some code to completion in the Level blueprint before any Actors get their BeginPlay? At the moment empirically and searching online, there does not seem to be any guarantees, nor does the Level e.g. have a Construction script. I am using Unreal 5.1.1. thanks for any thoughts.

p.s. empirically by setting breakpoints on the Level’s BeginPlay vs. an Actor’s BeginPlay, the actor is getting the event first. (I don’t expect that is deterministic, tho, and is the opposite of what i want :slight_smile:

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.

many thanks for the run-down. scary money quote, “So instead of fixing load order bugs later, it is better to create code that does not care about load order.” totally agreed, i strongly prefer systems that either are 100% consistent – either by working the same everywhere, or by erroring consistently on things that are nondeterministic, know what i mean? software development is kind of a joke. no wonder the aliens avoid our planet like the plague.

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