Hitting ensure in AACtor::BeginPlay in an actor with ChildActorComponents

Hi,

We are hitting the ensure(ActorHasBegunPlay == EActorBeginPlayState::HasNotBegunPlay); in Actor.cpp.

The actor with the issue is A blueprint with several ChildActorComponents all added in blueprint as component (not through construction script nor eventgraph)
One of the childactor (not always the same, but each time only one) hits the ensure.

It does not happen anymore if I remove the following code (introduced in CL3002443:

if (UChildActorComponent* CAC = Cast(Component))
{
	if (AActor* ChildActor = CAC->GetChildActor())
	{
		if (!ChildActor->HasActorBegunPlay())
		{
			ChildActor->BeginPlay();
		}
	}
}

It seems to work fine for me to just remove that, but I assume it is not the best way.

One specificity of the BP is that its child actors have components that are asynchronously loaded.

I had time to debug that a bit, Our Blueprint is placed in a sublevel and the BeginPlay is actually called by ULevel::RouteActorInitialize() when streaming in the level

So I add in this function a check for ChildActor

if (bCallBeginPlay && !Actor->IsChildActor())
{
	ActorsToBeginPlay.Add(Actor);
}

instead of:

if (bCallBeginPlay)
{
	ActorsToBeginPlay.Add(Actor);
}

As the BeginPlay for the ChildActor is defered to be dealt by its owning actor, I think it should be ok, but if you have any feedbacks or another solution, I take it.

Thanks

Hi Christophe,

I’ve created a JIRA report for this as UE-32772. We’ll look for a better way to handle initialization after this change in CL3002443

Let me know if you have any more questions.

.Tom

Thanks Christophe, your fix is exactly right. I’ve applied it to the 4.12 release branch in CL# 3038513 and it will be a part of 4.12.5.

Thanks for your feedback. I keep it locally and wait for 4.12.5