• Unity
  • repeat to play animation is unnormal

There is an Non_Loop animation.
My case is 『Stop and hide the animation that maybe doesn't arrive the end frame. Next time I have to show and play it in first key frame. Then I will repeat it at same mode. 』 ! But I have a serious problem. First time playing animation is OK. And then I hide it. Next time when I show it , the animation is flash first then play the animation. My understanding the animation must return to setup pose then play animation ? How do I reslove it ? AnimationState.ClearTracks and skeleton.SetToSetupPose , but it doesn't work.

using Spine3.7 runtime and Unity 5.6.7

below is my code! Using ShowSpine() and HideSpine() ! And I use spine-example-demo animation to try and record it !

private Transform _trans_obj;
private SkeletonAnimation _spine_sa;

...

_spine_sa = _trans_obj.GetComponent<SkeletonAnimation>();

...

public void ShowSpine()
{
   if (_trans_obj)
   {
      _trans_obj.gameObject.SetActive(true);
      if(!_trans_obj.gameObject.activeSelf) _trans_obj.gameObject.SetActive(true);
      _spine_sa.AnimationState.SetAnimation(0, "sneak", false);
   }
}

public void HideSpine()
{
   //_spine_sa.AnimationState.ClearTracks();
   //_spine_sa.skeleton.SetToSetupPose();
   _trans_obj.gameObject.SetActive(false);
}

below is my record video.
https://gyazo.com/a6bee0878916457254ac9a8130275c3b
3rd second is show and play animation first time then
4th second is SetActive(false) to hide it .
5th second is show it and play it again. And the animation flash first and then play animation.

Thank you

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

In your case of disable / enable you can add a manual call to SkeletonAnimation.Update(time) to get rid of the single frame transition:

[...]
_spine_sa.AnimationState.SetAnimation(0, "sneak", false);
_spine_sa.Update(0);

Thanks your reply very much and

SkeletonAnimation.Update(0);

is work for our case.

Other question :

  1. Second time when I play it, it must return to "setup pose" or "the first key frame of animation" then play ?
  2. "single frame transition" >>> mean last key frame of animation to first key frame of new animation ?

Thank you!

Great to hear that its working.

seg0616 написал

1. Second time when I play it, it must return to "setup pose" or "the first key frame of animation" then play ?

I'm sorry but I don't quite understand your question. Could you please re-phrase it and post it again?

seg0616 написал

2. "single frame transition" >>> mean last key frame of animation to first key frame of new animation ?

This means the frame of the OldFrom animation that would follow at normal playback (so if you change to a NewTo animation in the middle of the OldFrom animation it will not be the last frame but a frame in the middle) to the first frame of the NewTo animation.

seg0616 wrote:

  1. Second time when I play it, it must return to "setup pose" or "the first key frame of animation" then play ?

Before resloved head of question, when I change to NewTo animation from OldFrom we thought the skeleton must to return "Setup Pose" first , and then play new animation. But your last reply already answer the question ^^.

thanks a lot

Thank you for the clarification, glad it helped. 🙂