• Unity
  • Mecanim issue: odd frame when instantiating a spine object

Hello,

I would like to get some help on a problem we have stumbled around when trying to use Mecanim with Spine (we are using the latest Spine version and Unity 2019.3.0f6).

Our issue is that we get every now and then an odd frame when switching from one animation to another (I'm attaching a small video and a Unity file so that you can get a better idea of things).

Our scene consists of one Spine prefab and one empty object to instantiate another copy of the very same prefab. We then run two scripts, one changing the animation of the Spine object prefab and another one spawning the other instance.

You can notice that sometimes, the spawned object wouldn't start directly playing the requested animation but instead display the first frame of another clip (this doesn't happen all the time).

If you check the video or the scene it's pretty obvious as the two clips are fairly different animations in both size and colour.

I would be very interested in hearing of any suggestions or idea on what's might be happening.

Related Discussions
...

Thanks for getting in touch and providing the reproduction assets right away!

In this case the problem lies with update order, which seems to be designed rather unfortunately in Unity:

  1. Your prefab is instantiated from InstantiatePrefab.Update()
  2. PlayAnim.OnEnable is called, changing the state of Animator.
  3. The Update() iteration unfortunately ends here (!), not calling Animator.Update() or SkeletonMecanim.Update().
  4. SkeletonMecanim.LateUpdate() is called, updating the mesh - unfortunately of the old, non-updated animation state

The solution for your problem requires two additional update calles to ensure that both the Animator and the SkeletonMecanim components receive their Update() call before LateUpdate().

void OnEnable()
{
    var animator = GetComponent<Animator>();
    animator.Play("Create");
    animator.Update(0); // add this call
    var skeletonMecanim = GetComponent<SkeletonMecanim>();
    skeletonMecanim.Update(); // and add this call as well
}

Thanks a lot, we have used your solution and fixed the problem.

Glad to hear, thanks for getting back to us.