I’m trying to set up weapon animations purely in C++. However, calling Montage_play does nothing. If I set up a mostly-blank animation blueprint that only includes the idle animation, or if I select ‘Use Animation Asset’ for Animation Mode on the first person mesh, the mesh will only play that idle animation and nothing else.
This code is almost entirely taken from ShooterGame:
float animTime = 0.1f; //Default value in case the animation can't be played.
// try and play a firing animation if specified
if (FireAnimation != NULL && playerViewMesh != NULL)
{
// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = playerViewMesh->GetAnimInstance();
if (AnimInstance != NULL)
{
animTime = AnimInstance->Montage_Play(FireAnimation, 1.f);
if (animTime < 0.1f)
{
//The function returns 0 if the animation can't be played.
animTime = 0.1f;
}
}
}
If the animation blueprint is set or if I’m using the asset, then Montage_play() returns successfully, with a time that is equal to the length of the animation according to the animation viewer. However, as I mentioned, nothing actually plays. The weapon model is locked in the idle animation.
If the blueprint is not set, then GetAnimInstance() returns NULL, which makes it impossible to play the animation.
Is there some setup I’m missing to be able to play animations from C++?
Thank you.