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.