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.