I discovered, that the “Event Begin Play” from my Actors are fired before my Game Mode, Player State or Level Blueprint is fired.
In this Order the “Event Begin Play” is fired:
Actors
Game Mode
Level Blueprint
Player State
My Questions:
Why does the Actors Begin Play load, before the other “Event(s) Begin Play” are loaded?
Where should I initialize my Actors, if I use Method from for example Level Blueprint?
Should I put the reference to the Level Blueprint to execute the Method for specific Actors on “Event Begin Play” ?
My Calculation Logic within Player State, which is needed within Actors and other Classes, is initialized to late. So the Order matters to me.
And the Order when which Event begin Play is fired should be known, because of initializing Stuff in general.
Your link just refers to a post from a user, which has written that he is not sure either and want to get the opinion of a pro.
In addition, the Event Begin Play Order of the other commentaries are not equal. Maybe the Event Begin Play did execute “randomly” orall mentioned Execution Orders within the post are wrong (cause they don’t match at all)
BeginPlay is called for each object when it’s ready. It is generally not wise to assume any other objects state at that point, even if you find it by debugging, because it may change. It is however, somewhat logical to assume that a Level is only ready after all of its preset actors are initialized.
OK, I understand your question a little better now. If you want to make sure that one thing happens after another one has been called try setting one to start after ‘event begin play’ and then the other one starts after a custom event then call the custom event in the first one.
I have had this issue myself with creating widgets and referencing the data in them causing errors because of the order things are initialized. My work around as it seems certain BPs are always slower than others is that if you need something to happen first put a small delay after begin play or whatever custom event that you don’t want to run until the first thing happens first. This has worked well for me in the past.
I heard some months ago “If you think that you need to Delay something to solve a simple Problem, just think again”.
And I’m pretty sure, that this is a very common thing, that shouldn’t solved with Delay at all.
I “solved” the Problem with register my Actors (10 Actors) to the GameMode and do Stuff within Level Blueprint with the Array of Actors I got stored in GameMode.
This is my “workaround”.
If anyone knows a better (common and/or performant) way to solve this common issue, feel free to post it here.
Whatever works for ya ha There are many ways to skin a cat, in my case delays were a simple fix. It is basically the same thing as creating a custom event and having it called in the order you like from the BPs you want. I spare myself the extra custom events simply by delaying the begin play event in certain BPs.
Your other questions are not so clear. It really depends on what you’re trying to achieve. If all your actors need information about the level and they all are pre-set then you can probably initialize them in the level blueprint, but if they are also dynamically spawned, then you’d want to initialize them after they have been spawned. It is not uncommon to divide the initialization process so different parts of it happen at different timings. I could perhaps help you more if you be more specific about what you are trying to do.
I have a similiar problem with “BeginPlay” execution order at the moment. I have a pretty complex level streaming setup and already had the problem with widgets refering to a my character while he was not initialized. My fix for that was that i dont create the widget on begin play. Instead of that i created a custom event that i called in my level streaming logic at the end to be sure everything is loaded and the character can be possesed. BeginPlay was too early for that.
But now i have the problem, that my AIController is referring to a “placed in the world” character with get controlled pawn and hes calling to early for that. A 0.5sec delay in the controller fixed it, but i dont think thats a proper fix for that
Please don’t advice such horrible solution to others, these hacks just ignore the actual problem and will only lead to more trouble the bigger your game becomes, it’s a precursor to a mess. (nothing personal though)
I had this issue, so my perfect workaround is to create a custom event for the actor and put all the begin play code in there. Then, I call it in my game mode blueprint or whatever BP you chose to be the mediator or master. Sometimes, the bigger BPs still arent ready, so I set a timer to run in the mediator until that actor is valid and then it runs its begin play code and the timer then closes itself.