Playing animation through code

Hello im trying to play a animation through my c++ code for when the ai hits the player. Ive used breakpoints to see if the method is being called and it is however the animation doesn’t seem to be played. The code im using is :

if (attackAnimation != NULL)
{
// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = Mesh->GetAnimInstance();
if (AnimInstance != NULL)
{
AnimInstance->Montage_Play(attackAnimation, 1.0f);
}
}

. Ive set the attackAnimation in the components page in the blueprint so it should work just fine .