# UChildComponentActor-\>CreateChildActor Compile Error

**URL:** <https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 19, 2014, 2:43am UTC](https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064 "2014-09-19T02:43:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo.0263\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@leo.0263\_1](https://forums.unrealengine.com/u/leo.0263_1)\
**Post date:** [September 19, 2014, 2:43am UTC](https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064/1 "2014-09-19T02:43:26Z")

</div>

I’m trying to replicate [this tutorial](https://forums.unrealengine.com/showthread.php?4157-Blueprint-Tutorial-Multiple-Camera-Angles) to C++ based project. I have successfully do it in Blue Print before. I’m stuck on imitating the SetViewTargetWithBlend() function. On proper inspection I found that the ChildActor that i throw to that function is actually NULL. Which makes me suspicious that the ChildComponentActor is not poperly Created.

So I add CreateChildActor() to the UChildActorComponent in hope that this function will initialize the assigned child (camera) of my ChildActorComponent. But this throws a Compile Error :

```
error LNK2019: unresolved external symbol "public: void __cdecl UChildActorComponent::CreateChildActor(void)" (?CreateChildActor@UChildActorComponent@@QEAAXXZ) referenced in function "public:__cdecl ATutorialThirdPersonCharacter::ATutorialThirdPersonCharacter(class FPostConstructInitializeProperties const &)" (??0ATutorialThirdPersonCharacter@@QEAA@AEBVFPostConstructInitializeProperties@@@Z)

```

Here’s my code so far :

On Character.h I add a USpringArm and UChildActor component :

```
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = InventoryCamera)
    		TSubobjectPtr<class USpringArmComponent> InventorySpringArm;
    
    	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = InventoryCamera)
    		TSubobjectPtr<class UChildActorComponent> InventoryCamera;

```

On Character.cpp Constructor I add this code to Initialize those Actors :

```
    	InventorySpringArm = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("InventorySpringArm"));
    	InventorySpringArm->AttachTo(CapsuleComponent);
    	InventorySpringArm->bUseControllerViewRotation = false;
    
    	InventoryCamera = PCIP.CreateDefaultSubobject<UChildActorComponent>(this, TEXT("InventoryCamera"));
    	InventoryCamera->ChildActorClass = UCameraComponent::StaticClass();
    	InventoryCamera->CreateChildActor(); // <-- this code throws a Compile Error
    	InventoryCamera->AttachTo(InventorySpringArm);

```

And then I create simple on keyboard press event handler to change the camera which basically said :

```
APlayerController* const MyPlayerController = Cast<APlayerController>(GEngine->GetFirstLocalPlayerController(GetWorld()));
MyPlayerController->SetViewTargetWithBlend(InventoryCamera->ChildActor);

```

Please help, is there any-way I could replicate the usage of ChildComponentActor Blue Print in C++? Or did I not do it properly?

Thanks.

---

<div class="post-metadata">

**Author:** ![evillego6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@evillego6](https://forums.unrealengine.com/u/evillego6)\
**Post date:** [October 14, 2014, 10:36pm UTC](https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064/2 "2014-10-14T22:36:25Z")

</div>

Did you ever make any progress on this? Running into the same problem myself.

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [December 19, 2014, 5:53pm UTC](https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064/3 "2014-12-19T17:53:55Z")

</div>

Just like OP I’m trying to find the C++ equivalent of AddChildComponentActor with no luck. Did anyone figure this out?

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [December 19, 2014, 7:13pm UTC](https://forums.unrealengine.com/t/uchildcomponentactor-createchildactor-compile-error/294064/4 "2014-12-19T19:13:12Z")

</div>

I had the same issue, below worked for me:

Instead of CreateChildActor (which doesn’t seem accessible with the default build modules) manually call OnComponentCreated like this childActorComponent-\>OnComponentCreated();

There seems to be a bug where this particular function is not automatically called in C++ alone (the blueprint node AddChildActorComponent works fine) and the ChildActor within your component ends up never being created unless you use the manual workaround.

See this thread for more details:

> **[OnComponentCreated not called when using CreateDefaultSubobject?](https://forums.unrealengine.com/questions/41202/oncomponentcreated-not-called-when-using-createdef.html)**
>
> OnComponentCreated is called as part of the Spawn process. In AActor::PostSpawnInitialize we dispatch the OnComponentsCreated call which does the set up, then they get registered. If you want to manipulate the ChildActor from the owning Actor in...
