AddChildActorComponent from construction script in PIE cause pending kill problems

Branch: tested with promoted branch (66a699f)

Build version: 4.12.0-0+UE4

Detailed description of the issue:

In the construction script of an actor in my level, I create some child actors using an “Add Child Actor Component” node and store the actors for later usage in an array variable. But since I updated from 4.10.2 to the promoted branch, I get these error messages, when I play the level in the editor and it tries to use the child actors saved in the array variable:

Error Cannot access
‘DESTROYED_SymbolBlock_C_CHILDACTOR_21’.
It is pending kill. Property:
‘CallFunc_Array_Get_Item3’ from node
Set Symbol in graph ‘ChooseNewSymbols’
in blueprint MainBoard

Error Cannot access
‘DESTROYED_SymbolBlock_C_CHILDACTOR_19’.
It is pending kill. Property:
‘CallFunc_Array_Get_Item3’ from node
Set Symbol in graph ‘ChooseNewSymbols’
in blueprint MainBoard

[…]

I debugged the code and compared the source of 4.10.2 and the promoted branch and found that this code was added inside Engine\Source\Runtime\Engine\Private\Components\ActorComponent.cpp: UActorComponent::RegisterComponentWithWorld():

	if (!bHasBeenCreated)
	{
		OnComponentCreated();
	}

The problem with child actor components here is, that UChildActorComponent overrides this method in Engine\Source\Runtime\Engine\Private\Components\ChildActorComponent.cpp like this:

void UChildActorComponent::OnComponentCreated()
{
	Super::OnComponentCreated();

	CreateChildActor();
}

Which leads to the child actor to be killed / marked for pending kill:

void UChildActorComponent::CreateChildActor()
{
	// Kill spawned actor if we have one
	DestroyChildActor();

This wouldn’t be a problem, if the construction scripts would be called in PIE mode, but the bRerunConstructionScripts parameter of ULevel::IncrementalUpdateComponents() is false and thus they are not called. As a result, the array (already initialized by the editor) contains references to child actors marked as pending kill.

Here are the blueprints for reference:

Hello,

I have attempted to reproduce your issue, but I’m not seeing any error messages when I use your blueprint setup and PIE.

Have you tried recreating a simple test in this branch without using an upgraded project? If not, could you go ahead and try and let me know if you are still seeing the same error? If you do get the same error in a clean project, please provide the repro steps so that we can reproduce it on our end.

Thank you

Hi Sean,

thanks a lot for looking into this! Well, the “and it tries to use” of

when I play the level in the editor
and it tries to use the child actors
saved in the array variable

was not part of the reference blueprints.

You should be able to easily reproduce the error messages by adding a simple usage in the BeginPlay event of the “MainBoard” actor:

78277-addchildactorcomponent-pendingkill-in-pie-usage.png

Sadly, I cannot try now, because I already fixed it for me by not calling OnComponentCreated() and for some reason Visual Studio thinks that it has to rebuild the whole engine, when I put it back into the code…

Thank you for the clarification. I have tried to reproduce this issue again using the method you suggested below, but I still have not been able to nail it down.

It sounds like you were able to resolve the issue in your current project, is that correct?

Not really, I just removed the code killing the child component, with unknown consequences for the rest of the engine :wink:

As you tried again without succeeding, I installed the current 4.11.0 Preview 5 (Build version: 4.11.0-2858478+++UE4+Release-4.11). I’m still able to reproduce the problem with my project.

Repro steps for a minimal test case:

  • Open the official Unreal Engine 4.11.0 Preview 5
  • Create new “blank” project without starter content
  • Create a new blueprint class based on Actor, call it Block
  • Select the floor object of the level and click on “Blueprint/Add Script” in the details tab
  • In the Floor_Blueprint blueprint editor:
    • Add a variable named “ChildActorVar” of type Actor reference
    • In the Construction Script:
      • Add a “Add Child Actor Component” node, choosing “Block” as Child Actor Class
      • Take the return value and choose “Get Child Actor”
      • Assign the child actor to the variable “ChildActorVar”
    • In Event Graph:
      • From the “Event BeginPlay” node create a “Print String” node
      • Drag the “ChildActorVar” as “Get” into the blueprint and choose “Get Actor Eyes View Point”
      • Connect the “Out Location” value with “In String” from the “Print String” node
    • Compile the blueprint
  • Play the level → “X=0.000, Y=0.000, Z=0.000” is displayed, should be “X=0.000, Y=0.000, Z=20.000”,
    as the floor in a blank project is at Z=20cm
  • Stop the level → “Errors/warnings reported while playing in editor”:
    Error Cannot access ‘DESTROYED_Block_C_CHILDACTOR_6’. It is pending kill. Property: ‘ChildActorVar’ from node Print String in graph ‘EventGraph’ in blueprint Floor_Blueprint

Note: If you directly use GetDisplayName from the ChildActorVar in the event graph, there will be no error.
You can also add a string var to the block and try printing this on begin play. Also errors.

No error with 4.10.2.

Hello,

Thank for providing clear repro steps. I have been able to reproduce your issue, and have entered a bug report (UE-27008). I will provide updates on this issue as they become available.

Have a great day