BeginPlay strange behaviour

Hello! Faced very strange behaviour with BeginPlay on 4.26:

Scenario 1:

  • Play level in Editor
  • Level BP Begin Play called
  • Actors Begin Play called

Scenario 2:

  • Recompile Level BP (no code changes)
  • Play level in Editor
  • Actors Begin Play called
  • Level BP Begin Play called

It seems that something strange is around generated code. Or maybe my Level BP has old compilation results. Recompilation with no code changes cause reordering of execution flow…

Found out that Level BP Begin Play is called through special ALevelScriptActor, so that can be the thing…

I can’t recall exactly how this goes, but you can’t rely on one begin play being called before another. Here, it does depend on when you compiled relative to which code you refreshed last ( I think ).

Another example is the most recently placed actor’s input will be serviced before others.

It’s much better to not assume anything in this area.

If you want to force one actor to trigger before another you can change which part of the tick they are run in:

1 Like

C++ solution - you can use OnWorldBeginPlay event of UWorld class, it is broadcasted just after all Actors BeginPlay