void UAnimInstance_Player_PnC::NativeUpdateAnimation(float DeltaSeconds)

    APlayer_PnC* owningActor = GetOwningActor();

    if (owningActor != nullptr)


I realise this is more of a C++ type question than game dev specific, however I have noticed when I ask on Stack Overflow I get a C++ answer which is often not compatible with Unreal Engine way of doing C++.

I may be wrong, but I thought a child class has an "is a" relationship with its parent classes. So I thought that if I have APlayer_PnC : public ACharacter (which ACharacter is of course extending APawn , and then AActor), I would be able to 'find' it using the GetOwningActor function.

It gives the error AActor* cannot be used to initialize type APlayer_PnC* . I get it that I can just change that to AActor, but I need a variable that is part of the APlayer class.

What can I do to get access to a public variable in my APlayer_PnC instance.

The function I posted above is located in my custom AnimInstance class, which I have set my Player Blueprint to use and have re-parented the Anim Blueprint to my AnimInstance, but the variables do not show up.

I can post the full code if that will be of use, let me know.


  • 1
    \$\begingroup\$ Are you not missing a cast here? Every APlayer_PnC is an AActor (so you can assign a value of type APlayer_PnC to a variable of type AActor without an explicit cast), but not every AActor is an APlayer_PnC (so the return value from GetOwningActor might not be an APlayer_PnC at runtime, and so you need a bit of code to validate that it is before assigning). I'm not an expert in Unreal, but that looks to me like general C++, not something gamedev-specific. \$\endgroup\$
    – DMGregory
    Sep 2, 2021 at 14:20
  • \$\begingroup\$ many thanks for the super quick help guys \$\endgroup\$ Sep 2, 2021 at 14:29

1 Answer 1


The GetOwningActor returns an Actor. You need to cast to your specific class.

In this case: APlayer_PnC* owningActor = Cast<APlayer_PnC>(GetOwningActor());

  • \$\begingroup\$ Thank you so much. I had tried it with 'static_cast<>' and it didn't work. \$\endgroup\$ Sep 2, 2021 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .