Interaction between animation blueprint and C++

I’ve stepped through the C++ FPS tutorial and have a question about the interaction between animation blueprint and making calls to play animations from C++ code.

After looking at the Epic’s “Shooter Game” code, it looks like they call Montage_Play() from C++ code:

float AShooterCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
{
    USkeletalMeshComponent* UseMesh = GetPawnMesh();
    if (AnimMontage && UseMesh && UseMesh->AnimScriptInstance)
    {
	    return UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
    }

    return 0.0f;
}

AShooterWeapon::OnEquip() calls AShooterWeapon::PlayWeaponAnimation() which calls the above function on the Pawn to start playing the equip weapon montage.

My limited understanding of animation blueprint is that you set state variables in the Event Graph which drive the state machine in the AnimGraph to determine the animation which is played.

In my test code, I called USkeletalMeshComponent::PlayAnimation() on my pawn’s “FP_Hands” mesh to play the animation for equipping the weapon. After the animation played, the hands didn’t go back into another animation like I had hoped but instead went back to the generic (unanimated) “hands at sides” pose.

When should PlayAnimation() or similar functions be called directly from C++ code? How do these direct “play animation” calls interact with the animation blueprint?

Stil a bit new to Unreal and would appreciate any explanation of the “equip weapon” process for a C++ based game.

What did you use for arguments on USkeletalMeshComponent::PlayAnimation()? I’m still fairly new myself to Unreal but I believe that when you call PlayAnimation it switches your animation mode from Anim_Bp to Animation Asset, effectively overriding the Anim BP. So in order to get back you need to switch the Animation mode back to BP after the animation has completed.

You can probably see this by going to your skeletal mesh during game play and viewing the “Animation Mode” within the blueprint before and after your call of PlayAnimation. Hope this helps.