Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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->bUseControllerViewRotation = false;
         InventoryCamera = PCIP.CreateDefaultSubobject<UChildActorComponent>(this, TEXT("InventoryCamera"));
         InventoryCamera->ChildActorClass = UCameraComponent::StaticClass();
         InventoryCamera->CreateChildActor(); // <-- this code throws a Compile Error

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()));

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


Product Version: Not Selected
more ▼

asked Sep 19 '14 at 02:43 AM in C++ Programming

avatar image

6 1 1 4

avatar image evillego6 Oct 14 '14 at 10:36 PM

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

avatar image VSZ Dec 19 '14 at 05:53 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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: https://answers.unrealengine.com/questions/41202/oncomponentcreated-not-called-when-using-createdef.html?sort=oldest

more ▼

answered Dec 19 '14 at 07:13 PM

avatar image

939 24 28 55

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question