• Unity
  • Animation stops at the end of a timeline

Related Discussions
...

Hi,
I recently migrated my project from spine 3.8 to spine 4.0 everything went relatively smoothly so that is awesome.

However, I noticed something different. I'm using Unity timeline and at the end of my timelines I always add an idle clip with "loop" set to true in order for the character to get back to idle.

Prior to the migration, the idle would keep looping after the timeline director was finished playing. But now the character just freezes.

The animation on the skeletonAnimation is correctly set with the right animation and "loop" is ticked, but the animation just doesn't play.

I noticed that checking "don't pause with director" on the Animation State Clip fixes this, but what if I do want my animations to pause with the director? I suppose that's where the bug comes from, the clip probably thinks the director is paused. I can workaround the problem using that flag but it is a bit of a hacky way to deal with it and would require me to edit every single one of my timelines.

edit:
I did some research, and it appears OnBehaviourPause is indeed called when the director becomes inactive (which includes getting at the end of the graph)
https://forum.unity.com/threads/code-example-how-to-detect-the-end-of-the-playable-clip.659617/

so in SpineAnimationStateMixerBehaviour.cs you could fix this like so:

public override void OnBehaviourPause (Playable playable, FrameData info) 
{
     var duration = playable.GetDuration();
     var count = playable.GetTime() + info.deltaTime;
 
 if ((info.effectivePlayState == PlayState.Paused && count > duration) || playable.GetGraph().GetRootPlayable(0).IsDone())
    return;

 if (!dontPauseWithDirector) {
    if (!isPaused)
       HandlePause(playable);
    isPaused = true;
 }
}

I've tested the modification in my project and that solved it, but I suppose you guys might want to test it more thoroughly (or perhaps that was the intended behaviour all along, if that's the case I'd love to know).

Thanks for reporting and providing a solution to your issue up front. Unfortunately you seem to not be using the latest version of the Spine Timeline extension package, as this has already been resolved. There is a Don't End with Clip property which can be enabled. We would always recommend to check out the download page and search the forum before implementing any bugfix yourself.

Please note that the 3.8 to 4.0 upgrade guide describes any behavioural changes and necessary actions to receive the old behaviour:
Spine-Unity 3.8 to 4.0 Upgrade Guide

There has been some discussion here on the forums:
Spine 4 Timeline Extension - Pausing at end of track
PlayableDirector not satrting after it was paused.

Oh thanks, that's good to know. I did do a little search but probably didn't type the right search terms.

Am I right in assuming that "don't pause on end" flag will be set to false by default and that I'm going to have to update all my timelines? I understand the necessity to behave like Unity Animations on the timeline though.

If I understand correctly, now, when a clip is finished it will be playing the empty clip? I'm animating on multiple tracks and I've had issues when a finished clip on track 1 was animating a bone that is animated on track 0 afterwards. The workaround for me was to add an empty animation clip on track 1 to make sure there were no interactions (that problem, by the way, only happens in play mode). Am I understanding correctly that with the new runtime, I will no longer need to add those empty animation clips?

gofiguregames escreveu

Am I right in assuming that "don't pause on end" flag will be set to false by default and that I'm going to have to update all my timelines? I understand the necessity to behave like Unity Animations on the timeline though.

Yes, it will be set to false by default. If you want to avoid having to setup each clip manually, you could also speedup the process by the following:

  • Change the default value of dontEndWithClip = false to dontEndWithClip = true in SpineAnimationStateBehaviour.cs here. Then you can save your timeline assets if they have not already written the new dontEndWithClip parameter to disk. Afterwards you can either revert the code change, or leave it as is if you prefer that.
  • If your Timeline assets are already saved with the new parameter, you can open all Timeline.playable asset in a text editor and search for dontEndWithClip: 0 and replace all occurrances with dontEndWithClip: 1. Visual Studio Code for example would allow you to open a folder and search all subfolders and replace the string accordingly.
gofiguregames escreveu

If I understand correctly, now, when a clip is finished it will be playing the empty clip? I'm animating on multiple tracks and I've had issues when a finished clip on track 1 was animating a bone that is animated on track 0 afterwards. The workaround for me was to add an empty animation clip on track 1 to make sure there were no interactions (that problem, by the way, only happens in play mode). Am I understanding correctly that with the new runtime, I will no longer need to add those empty animation clips?

Yes, empty space on a timeline track will now automatically set the empty animation. Thus your workaround of setting an empty clip manually should now no longer be necessary.

While we understand that it can be annoying when behaviour changes after upgrading, we also hope that the changes make Timeline usage much more intuitive now, and to keep it more consistent with typical Timeline behaviour.