Set animation property in AnimBP

If I have a skeletal mesh in a blueprint with an animation blueprint how do I access the animation blueprint of that mesh such that I can set a variable inside the animation blueprint from the character blueprint to make custom modifications to the animation variables during runtime? Is this possible?

Of course. It’s actually how you are supposed to do it.
The wrong way is to access the player in the animation blueprint.

Drag from the mesh, search animation blueprint.
Once you find it, you have to cast to your blueprint type to access its variables.

Place that bit of code after a 2sec delay inside a BeginPlay node.
The delay prevents the mesh animation blueprint from not existing in most cases.

After the cast, create and set a variable.

Before you use the variable you create, validate it at least once - this prevents errors from happening when the variable goes bad or if initialization failed.

You may want to consider doing all of this in c++.
You create your master character class and then just set the class of your characters to it.

Doing it via c++ allows you to have clean access to the variable in BP without having to manually cast.
Though you have to solve the reference to create the cast in c++.
Regardless of how you get to it you always need to cast…

Do I have the right idea? If I cast like this it’s a type mismatch.

Should it be a class reference?

Try getting the anim instance of your skeletal mesh 2 and cast that to the desired animbp object (not class). Also, you don’t need to perform the cast on tick, it would be better on Begin Play, then store that cast reference in a variable.

1 Like

Definitely do not cast on tick. Ever.

I won’t, thanks for the advice. Why shouldn’t I cast on tick?

It’s an expensive operation to begin with.
Doing it evert tick is going to lead to issues.