• Unity
  • SetToSetupPose() and Mecanim

Related Discussions
...

In the project I'm currently working on we don't need any dynamic slot stuff so we had previously been keyframing everything at the start of the animation. I recently spotted on here while looking for something else that it was recommended to call SetToSetupPose() at the start of the animation so I've been trying that out instead. Is there a particular place that you would recommend to do this when using mecanim? At the moment I'm using an animation state behaviour and calling SetToSetupPose() when the state starts as shown below:

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
      var spineRenderer = animator.gameObject.GetComponent<SkeletonAnimator>();

  if (spineRenderer == null)
     return;

  spineRenderer.Skeleton.SetToSetupPose();
}

This seems to work, but occasionally I get a flash of the setup pose displaying when the animation starts. This wouldn't be a problem but sometimes the animators leave slots active that they shouldn't in the setup pose and so you get an unwanted slot flashing up on screen for one frame. Is there anything I can do to ensure that the first frame displayed is the first frame of the animation itself? I'll probably ask the animators to clean up the setup pose anyway but I'd rather not have to rely on that if at all possible.

10달 후

I had a similar problem, and was able to fix it by calling Skeleton.SetBonesToSetupPose (instead of SetToSetupPose). This resets the poses of the bones but doesn't change the state of the slots (there is an alternate SetSlotsToSetupPose for that purpose).

My StateMachineBehaviour looks like this:

using UnityEngine;

public class ResetPoseBehaviour : StateMachineBehaviour
{
   public override void OnStateEnter(Animator _animator, AnimatorStateInfo _stateInfo, int _layerIndex)
   {
      if (!gotSkeletonRenderer_)
      {
         skeletonRenderer_    = _animator.gameObject.GetComponent<Spine.Unity.SkeletonRenderer>();
         gotSkeletonRenderer_ = true;
      }

  if (skeletonRenderer_ != null)
     skeletonRenderer_.skeleton.SetBonesToSetupPose();
   }

   private bool                         gotSkeletonRenderer_;
   private Spine.Unity.SkeletonRenderer skeletonRenderer_;
}

You can also force the skeleton to update immediately after setting it to the setup pose

skeleton.Update()

A bit heavy-handed, but prevents the 1-frame error.

Hi,

great tips, thanks guys!

Quick follow up question: If you call skeleton.Update(), it requires a float time value, does it matter what I put in there? I guess 0.0f?

About Mecanim: If I reset the anim and on state enter, I guess it then is nonetheless able to interpolate between the animations correctly?

Cheers!

0f - you don't want the animation timing to change, you just want it refreshed.

I haven't noticed any problems with Mecanim blending/interpolation in my project.

I believe that the blend result will immediately overwrite most of the properties that are reset in OnStateEnter. The problem arises from the properties that are not being written by the blend result, and those should now be in "setup" pose rather than whatever pose was last written by an animation.

7달 후

Hi,

I have the same issues, but since my anims also change the visibility of certain items(and they actually don't in Unity, latest runtimes 17 Jan 2017), I need both the bones and the slots to be refreshed.

So I need to call spineRenderer.skeleton.SetToSetupPose()

yet some props that shouldn't be visible still pop in for a frame. The animator got crazy keying all the animations for all the skins, but no success.

I'm also trying to call spineRenderer.skeleton.Update(<any value>) but has no effect today, it's still glitching.

How is possible this kind of issues still persist after a year? Am I doing something wrong?

@NeatWolf, this thread is talking about an older version of SkeletonAnimator.

If checking the "Auto Reset" checkbox doesn't work, can you send us your assets, and we can investigate? contact@esotericsoftware.com

6일 후
Pharan wrote

@[삭제됨], this thread is talking about an older version of SkeletonAnimator.

If checking the "Auto Reset" checkbox doesn't work, can you send us your assets, and we can investigate? contact@esotericsoftware.com

Where is the "Auto Reset" checkbox? I have problems with SetToSetupPose not working sometimes. I'm not using mecanim, just code.

If you're on 3.5, the AnimationState auto-resets all the time. If you're not using Mecanim, you're in the wrong thread. Can you open a new topic and describe what problem you're having?