What C++ class can I use for animation states?

I’d like to get information about some some states within my Player’s animation blueprint. What class can I use to reference that particular animation blueprint so that I can get information such as the current state within that animation blueprint?

I’ll take a crack at it, but the following code is unverified and simply constitutes an educated guess:

Code should be prefixed with this in order to access the Animation Blueprint from code:

if (UAnimBlueprintGeneratedClass* AnimBlueprintClass = Cast<UAnimBlueprintGeneratedClass>((UObject*)GetClass())) {...

I’m assuming this code is being called from an UAnimInstance derived class. If not, use your anim instance in the above class: (i.e. YourAnimInstance->GetClass()).

An AnimBP can have many state machines. To go through all of them:

for(i = 0; i < AnimBlueprintClass->AnimNodeProperties.Num(); i++) { ...

When you find the right one, make a node of it:

MachineIndex = i;

You can find information about each state machine (such as their name, if you’re looking for the right one by name) through the AnimNodeProperties array:

const int32 InstancePropertyIndex = AnimBlueprintClass->AnimNodeProperties.Num() - 1 - MachineIndex;
UStructProperty* MachineInstanceProperty = AnimBlueprintClass->AnimNodeProperties[InstancePropertyIndex];

Once you have that, the actual state machine structure is accessed like this:

FAnimNode_StateMachine* MachineInstance = MachineInstanceProperty->ContainerPtrToValuePtr<FAnimNode_StateMachine>(this);

Once again, the “this” is assuming your calling this from an UAnimInstance derived class, if not put your UAnimInstance reference there.