Getting actor reference in Actor Component?

Hello! I am having an issue getting a reference to an actor in an ActorComponent class… I try to use

    APawn* Pawn = TryGetPawnOwner();
    AZephyrCharacter* Character = Cast<AZephyrCharacter>(Pawn);

I have used this method inside of an AnimInstance class, and it works successfully. I have added #include

#include "GameFramework/Pawn.h"

To my header file for the ActorComponent as well.

Any help would be greatly appreciated!

P.S. I noticed you can not even use the TryGetPawnOwner node in a ActorComponent blueprint either… There must be a way?


auto myPawn = Cast<APawn>(GetOwner());

Ah! Feeling like an idiot. Thanks so much EvilCleric!

It’s important to invest some minutes a day into reading Game Framework classes in source and/or API online pages.

You make yourself more familiar with what the engine can do and when the API changes it’s easier for you to know where and what you have to refactor in your code.

Hmm. Which game framework should I have looked up? Actor component?

Currently reading Tom Loomans Game framework c++ guide!

You have no idea how many dots you just connected for me… Thank you SO much… I have a lot to learn. :slight_smile:

1 Like