How to get Animation Blueprint refrence for casting

My apologies, I should have just given you an example without assuming your knowledge…

Here’s how you reference your animBP from any blueprint, level, character or custom:

The way casting works is you’ve got a generic object, in this case, the Player Character node. Casting is a way of saying, check to see if this generic PlayerCharacter is actually My Specific Player Character. If it is, then you can access the specific variables you create inside your character. If it’s not, then it will fail.

Then with your player character, there’s ALWAYS a skeletal mesh. This is inherited from the base code. So you can always get the mesh from any character. Whether or not a mesh has been set is another thing entirely. Once you get the mesh, it usually comes with an associated AnimationBP (provided you’re using it as a character mesh) so you need to grab a reference to the Generic animationBP which is done with the AnimInstance node and then you have to see if this generic animbp is actually using your Specific animBP. If it is, then you can access all of your custom variables from within the animBP.

You don’t necessarily need to create a duplicate variable inside your character, you could skip that step and just go straight into setting the variable inside your animBP but it’s easier to reference the character and simply adjust it’s variable and have your animBP getting a reference to the var inside your character to drive its own values.
To do that, inside your animBP’s event graph you would get a reference to the PlayerCharacter again and then grab the variable inside it and use that to set the var inside the animBP like this:

Then from whatever BP you like, you can simplify the code by only getting a reference to your character and then setting its custom variable value and that will auto-populate to your animBP.

2 Likes