Wich begin first? Actor vs Actor component

Hello everyone! I’ve a simple question… I’ve an actor with some actor component, I was wondering wich begin play is the first one? We suppose that the first one should be the Actor’s component one because the actor may need to access to actor’s component variables. But we’re not sure about it haha. Thanks for your help!

have you tried to just put a print on each begin play to see?

We thought about it, but that’s not precise, we prefer to know the cycle of the engine…
Just found this: Actor Lifecycle
We supose that “Initialize components” means the begin play of the components, but is better to ask the community haha

if you want to make sure one fires after the other you can simply use a delay node, or fire off an event to announce when something is ready and for others to follow.

You should never rely on the order of BeginPlay. Components and actors can be created at any time which means BeginPlay will be able to execute at any time. There are other conditions in which the order will vary.

You should keep component related code out of the actor and make the actor communicate to the component through delegates, which you can set up on BeginPlay.

Excuse me for the formatting but long ago (UE4.26) I wrote down some order in which methods are executed. Obviously it is not complete as the original c++ is but it’s a rough guideline… Indentation means a method calls another, no indentation means execution from top to bottom.:

UWorld::SpawnActor
-AActor::PostSpawnInitialize
--AActor::RegisterAllComponents
---AActor::PreRegisterAllComponents
---UActorComponent::RegisterComponent
----UActorComponent::RegisterComponentWithWorld
-----UActorComponent::OnComponentCreated
-----UActorComponent::InitializeComponent
-----UActorComponent::BeginPlay
---AActor::PostRegisterAllComponents
--AActor::PostActorCreated
--AActor::FinishSpawning
---AActor::ExecuteConstruction
----AActor::OnConstruction
---AActor::PostActorConstruction
----AActor::PreInitializeComponents
----APawn::PreInitializeComponents
----AActor::InitializeComponents
-----UActorComponent::InitializeComponent
----AActor::PostInitializeComponents
----APawn::PostInitializeComponents
-----AController::Possess				
----AActor::DispatchBeginPlay
-----AActor::BeginPlay
------UActorComponent::BeginPlay
-------UActorComponent::ReceiveBeginPlay
------AActor::ReceiveBeginPlay

So according to what I wrote back then, BeginPlay should execute first on the ActorComponent in most situations. But again, don’t ever use BeginPlay in an order related way because this will not always be the case. :slight_smile:

2 Likes

Delay is a recipe for disaster, turns the whole situation into guesswork

4 Likes

“initialize” is not the same as “begin play”

Also, replication (for networking) may cause surprising reordering of “begin play.”

In general, if you have a strict ordering requirement, it’s better to have some function that checks whether all the necessary bits are in place, and then does the thing it needs to do once all of them are. You can then call this from all the different places.

Fairly sure in Unreal 5 (I just tested in 5.3 PIE), actorcomponent BeginPlay occurs before Actor BeginPlay.

1 Like