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:


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

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.

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

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