# AddChildActorComponent from construction script in PIE cause pending kill problems

**URL:** <https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064>\
**Category:** Blueprint\
**Tags:** child-actor-componen, pie, unreal-engine, construction-script, bug-report, question\
**Created:** [February 10, 2016, 9:44pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064 "2016-02-10T21:44:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimmick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grimmick](https://forums.unrealengine.com/u/Grimmick)\
**Post date:** [February 10, 2016, 9:44pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/1 "2016-02-10T21:44:12Z")

</div>

**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:

 ![78139-addchildactorcomponent-pendingkill-in-pie.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/e/69e6ff335e4b1aad3faca9c2fc009cc5e056bcb2.png)

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [February 11, 2016, 3:17pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/2 "2016-02-11T15:17:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Grimmick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grimmick](https://forums.unrealengine.com/u/Grimmick)\
**Post date:** [February 11, 2016, 9:48pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/3 "2016-02-11T21:48:52Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/7/fb789d4270be86936f8853ed6e015c774bc9c446.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…

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [February 12, 2016, 1:29pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/4 "2016-02-12T13:29:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Grimmick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grimmick](https://forums.unrealengine.com/u/Grimmick)\
**Post date:** [February 12, 2016, 10:55pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/5 "2016-02-12T22:55:32Z")

</div>

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

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.

 ![78409-addchildactorcomponent-pendingkill-in-pie-minimal-testcase.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/e/60ed52055b6876a5d8c5ad46b1d4b6c94b89cc84.png)

---

<div class="post-metadata">

**Author:** ![Sean\_Flint](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sean\_Flint](https://forums.unrealengine.com/u/Sean_Flint)\
**Post date:** [February 16, 2016, 7:46pm UTC](https://forums.unrealengine.com/t/addchildactorcomponent-from-construction-script-in-pie-cause-pending-kill-problems/347064/6 "2016-02-16T19:46:27Z")

</div>

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
