How to handle the Begin Play events for actors added in the editor?

Hi, I have a few actor blueprints that I have added to the level in the editor. All of them have executable code running as part of Event Begin Play. And in one case, the actor is referencing another one of these actors. It is running smoothly as this point, but I don’t think what I’m doing is safe practice.

What if the referenced actor [Let’s call it Actor B] has not finished initializing in time? So should I fire off that begin play functionality as part of a custom event that is called when the first actor [Actor A] goes through it’s begin play event to the completion?

You are right to think that it’s not safe practice but…

I believe that the execution order is based on the order that the object was placed (or spawned) into the editor (or world) so you should be able to control the order based on that fact, which means you should be fairly safe as long as you are aware of this.

Don’t take my word for it though… do some tests first to make sure this is always the case (in PIE and standalone).

If it’s not… well… you might have to do this on tick instead, maybe add a tick prerequisite (if that works the way I think it does :p).

Thanks, I had not thought about the relation of the order of placement in editor to the spawning of the actor in game. I will do some tests on that.

I’m also thinking of spawning the actors using blueprints rather than placing them in the editor. I’m not sure if the actors placed directly in the editor viewport, will spawn in the same order every time in all devices.

If you are needing Actor B to reference Actor A at spawn, then you should probably use a third script – level, game mode, ect – to control their actual spawning and set whatever you need to set. Without seeing what you are trying to accomplish though, I can’t recommend.

That is exactly what I wanted to know. Whether it should follow a manual code flow or just leave it to the editor. Thanks @The Britain. :slight_smile: