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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to add an ActorComponent created in blueprints to an Actor created in c++?

I have a custom ActorComponent created with blueprints. Now I am creating a new Character in code, but I haven't been able to find an example on how to add the component to the Character.

This is what I have so far:


 class ZOMBIECOUNT_API AZCParentCharacter : public ACharacter
     // Sets default values for this character's properties

     UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = ActorComponents)
     UActorComponent* ACTargetableComponent;


      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     static ConstructorHelpers::FObjectFinder <UActorComponent>ACTargetableC(TEXT("Blueprint'/Game/Blueprints/Components/AC_Targetable.AC_Targetable'"));
     if (ACTargetableC.Object != NULL)
         ACTargetableComponent = ACTargetableC.Object;

But when I open the project I get: alt text

If I create a blueprint based on AZCParentCharacter, it doesn't have the component in the components tab: alt text

The path to the component must be right because I right clicked it in the Editor, then clicked "Copy Reference", and pasted it in the function.

I have a feeling everything I've done is wrong lol. Any help is appreaciated.

Product Version: UE 4.8
notfounimag.jpg (24.9 kB)
imgcomponents.jpg (41.4 kB)
more ▼

asked Jul 14 '15 at 08:27 PM in C++ Programming

avatar image

677 33 107 127

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

1 answer: sort voted first

I haven't done this before but I have a few thoughts about what's wrong here

ConstructorHelpers::FObjectFinder ACTargetableC(TEXT("Blueprint'/Game/Blueprints/Components/AC_Targetable.AC_Targetable'"));

you need to load the blueprint first so change UActorComponent to UBlueprint, and get the components inside of it. You can get the detailed class structure in debugger, that's how I would do it

more ▼

answered Jul 15 '15 at 02:48 PM

avatar image

99 14 15 22

avatar image IDON_EAT_DOGS Jul 15 '15 at 02:50 PM

One thing I failed to mention is that you can create an object from bluerpint->GeneratedClass

(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