How to check if animation has finished?

Hi! I am playing an animation on a skeletal mesh component by using the following code:

m_pMesh->PlayAnimation(s_pAnimJump, 0);

where m_pMesh is of type USkeletalMeshComponent* and s_pAnimJump is of type UAnimSequence*.

This plays the animation perfectly! But I would like to know when the jump animation has finished so that I can play the free-fall animation. Does anyone know how to find the remaining time?

Thanks!

m_pMesh->PlayAnimation(s_pAnimJump, 0);
float animLen = m_pMesh->GetSingleNodeInstance()->GetLength();

If you wait for the animation to end, and then play the other, you’ll get a little hitch, so I would take a bit of time off:

animLen -= 0.34f;

Now you can set a timer or something to kick off the next step. For example:

GetWorldTimerManager().SetTimer(PostAnimTimerHandle, this, &MyActor::PostAnimFunc, animLen, false);

I recommend that instead of using m_pMesh->PlayAnimation(s_pAnimJump, 0); you use:

float animLen = m_pMesh->GetAnimInstance()->Montage_Play(MyMontage);

Because montages have the nice blend-in, blend-out feature, return the anim length right off the bat, and have many convenience functions such as pause and skip to section. If you don’t want a hitch between animations, simply account for the blend-out time.

animLen -= MyMontage->BlendOutTime;
1 Like

There is a method called IsPlaying() in USkeletalMeshComponent that will tell you if any animation is currently playing.

Ah, I couldn’t find GetSingleNodeInstance. I didn’t realize it was referring to an animation instance. I will check out montages because the blending will probably look much nicer than a snappy animation change. Thank you so much for taking the time to reply to my question! You have helped me so much.