- Edited
Fast forward an animation to near the end?
Hey there.
I need to do this in Unity: during a certain event, fast forward the current animation to the end and apply it's animation properties to the skeleton. I tried some stuff already like iterating over the track entries in the AnimationState and setting their time to 0.99f, but nothing I did seemed to achieve this result. Any tips?
There are some assumptions I can make for what you mean by "fast forward the current animation to the end and apply its animation properties".
Note that the current behavior of AnimationState is: it will not end an animation track entry automatically, even when the animation is not looping and the duration has elapsed.
So even if it has already played the animation's full duration, it will continue to apply whatever the last animation keys were set to for that animation.
So at whatever point, you would just go:
var currentAnimationTrackEntry = skeletonAnimation.AnimationState.GetCurrent(0); // get the currently playing animation TrackEntry
currentAnimationTrackEntry.TrackTime = currentAnimationTrackEntry.Animation.Duration; // Set the time to the
As long as nothing else is interrupting or changing animations on that track, the animation's last keys/pose will continue to be applied to the skeleton.
Also note that it will apply on updates. SkeletonAnimation's Update will update the AnimationState, and apply it to the skeleton, and SkeletonAnimation's LateUpdate will generate a new mesh based on that new skeleton pose.
If you do stuff before these updates methods can be called by the engine, you may not see the results right away, or at all if you interrupt AnimationState with some other changes.