Get character from animinstance?

Hi, in my current character class I do this:


AnimInstanceRef = Cast<UCharAnimInstance>(GetMesh()->GetAnimInstance());

To get the animinstance in my character.

But how would I do the other way around? I need to trigger a function in my character class once an animation has ended, but don’t know how to get a reference to my character.

Also, how do I avoid circular dependency? But still be able to trigger functions between the classes?

Create a delegate in your anim instance and then bind to it from your character sounds like the easiest way.

Or create a public function in your character that ypu call from the anim instance. Cast to get owner to get your character.

Not sure how to do something like that I’m afraid.

I tried to forward my class in my animinstance header.h like this:


     class ATribesmenCharacter;
    ATribesmenCharacter* Char;

cpp:



   AActor* Char = GetOwningActor();


But the editor crashes when I try to launch it.

Sorry for necroing this old thread, but I’m once again needing to do this and couldn’t figure it out last time. Any ideas?




ATribesmenCharacter* Char = Cast<ATribesmenCharacter>(this->TryGetPawnOwner());



https://docs.unrealengine.com/en-US/…ner/index.html

Aaaaaah, thanks I was nearly there, just missing the ATribesmenCharacter* part.