How to get the C++ component's father character?

I created a C++ actor component in a blueprint character.

how can I get the character’s pointer in my component class?

if your finding it in c++ then

AActor* origin = this->GetOwner();
TArray<UActorComponent*> morphemeList;
morphemeList.Append(origin->GetComponentsByClass(UActorComponent::StaticClass()));

if you want to find it in blueprints then just stick GetComponentsByClass in

I want to get the character, not components…

So you want to get the owner character of the component

1 Like

Hi,

Give this a shot. Hope it helps.

 // include in your cpp
 #include "Kismet/GameplayStatics.h"
     
 // 0 refers to Player Index. 
 ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetOwner(),0);

Yes, that is what I want