• Unity
  • Why non-looping animation TrackEntries no longer stop.

  • Изменено
Related Discussions
...

I read this document links:http://en.esotericsoftware.com/spine-unity-events
And what makes me very confused is why the non-looping animation TrackEntries no longer stop.

After the animation is executed, it should end.This is a very natural idea. Why is it designed to be like this? What is the meaning of being stuck in the last frame.Generally speaking, an animation should end when it reaches the last frame.

The documentation says this is the default behavior. See below for more information on how to make this behave differently. But, I did not see the "non-default" part in the lower part. How to make this behave differently?

Say you have an animation, where the character raises their hand over multiple frames. You queue this animation on a track, non-looping. When the animation has reached the end, you want the character to keep its hand raised. For this to happen, the last frame of the animation needs to be applied. If it where not, the parts the animation keys would return to the setup pose, if no other animations on a different track keys these parts. This is generally not what you want for non-looping animations.

The reason it works this way is because animation state is essentially stateless. If we didn't keep the track entry for an unlooped animation around and applied it's last frame, we'd instead have to keep around all the states of the properties that animation modified, which gets extremely messy and error prone, and would do exactly the same as the solution we currently have, which is a lot simpler.

Note that you will still receice a "Completed" event when the non-looping animation has reached its end. You can react to that by setting a new animation or clearing the track. Alternativley, you can queue an empty animation (AnimationState.addEmptyAnimation()) or set TrackEntry.trackEnd to the animation's duration.

To add to Mario's nice explanation, looping is easy to understand, the animation doesn't end. For non-looping we need a default behavior. Sometimes you want an animation to continue playing, as Mario described. Sometimes you want it to end when it reaches the animation duration. Neither of these for the default would be wrong. Which you want depends on your animation and what you are doing in your game.

The reason we chose the default to be to continue playing the animation is that ending the animation abruptly is not usually what you want. Usually you want to use an empty animation afterward, so the skeleton returns to the setup pose over some time.

If you do want the animation to end abruptly, you can set TrackEntry trackEnd to the time you want the track entry to be removed:

entry.trackEnd = entry.animation.duration;

As the TrackEntry trackEnd documentation mentions, doing this will cause the skeleton to snap from the last frame of the animation to the setup pose.