UChildComponentActor->CreateChildActor Compile Error

I’m trying to replicate this tutorial 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.

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

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

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: