Cast to Character Blueprint inside Animation Blueprint

I spent 4 hours yesterday searching everything from Unreal documentation to YouTube videos, (before it blew up and stopped working), on a question I see posted by hoards of confused game designers: How do I get a Character Blueprint reference inside my Animation Blueprint, so I can access my custom character blueprint variables?

The Unreal documentation doesn’t give an example to do this. What everyone tries to do is drag from Try Get Pawn Owner to a Cast To custom_player_BP, but of course this fails. So you start trying a cast to Character, you try Get Pawn, you start trying everything, then slam your head into the desk and lie on the floor for an hour, wondering how this stupid task is so hard. You can watch it fail just by connecting the Cast Failed pin from the Cast when object is connected to Try Get Pawn Owner.

Well I just started guessing and THIS WORKS! I finally got access to my Player BP and variables. I resorted to guessing because literally nobody had a direct example.

Try Get Pawn Owner isn’t the right source is the best I can figure, but Get Owning Actor from the Event Graph seemed to be exactly what is needed to then Cast to your character blueprint.

If I’m NOT doing the right thing and you have deeper insight than I do into this, please let everyone here know – but this is working so far!

I really hope this helps others in the same boat!

Maybe its just lack of knowledge for these game designers, Try Get Pawn Owner works just fine and it will depend where your calling the cast also, you should be calling the cast on Event blueprint initialize animation then set a variable of your character class there rather than casting to it every time.

Also how is this related to UE5 ?

Try Get Pawn Owner cast to Player Character Blueprint fails from an Animation Blueprint Event Graph.

Then the issue is your end my friend, try logging the class off the pin.

Now you have me curious. I definitely don’t want to leave a bad piece of advice up top for anyone else.

When I print the “Try Get Pawn Owner” I get the name of my Blueprint. I can call functions directly on it such as GetActorRotation, GetVelocity etc without any casting. The problem here is I cannot access a custom variable that is defined on the Blueprint (in this case “Speed” or a new “Health” variable I’ve added.

If I try to drag a wire from the Blueprint var target pin to Try Get Pawn Owner, the editor shows an error, “BP_Player object reference is not compatible with Pawn Object Reference”.

If my method of Get Owning Actor is wrong to cast to the BP then get the variables set there, how would you access the character blueprint’s variables by starting with “Try Get Pawn Owner?”?

The whole thing is bad advice.

It’s supposed to go the other way around.
Animation BP is to have no code.

Character casts to animation BP and sets variables.

Ue4 Animation FastPath

For reasons why.

MostHost_LA is right you should only use the Anim BP for getters not setters, use it to drive your animations states.

But you will still need to cast to your character class, and for these custom variables have you set them to private? as you wont be able to access them if you have.

Example below of how you should cast to your character.

Up voted for “truth”. A animation BP should never be used as a coding extension but as a means for what ever is used to set the current required animation stae. Ideal the controller should be telling the animBP what is required and not have the animBP play 20 questions