x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.9
Tags:
more ▼

asked Dec 10 '15 at 06:27 PM in C++ Programming

avatar image

Rijke
16 5 4 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first
 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;
more ▼

answered Dec 11 '15 at 03:03 AM

avatar image

rantrod
1.5k 48 47 216

avatar image Rijke Dec 11 '15 at 03:57 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Dec 11 '15 at 02:18 AM

avatar image

Rijke
16 5 4 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question