• RuntimesUnity
  • Unexpected behavior with BoneFollower sprite

To change my skeleton animation's direction, I used the following code:

skeletonAnimation.Skeleton.ScaleX = spineModel.facingLeft ? -1f : 1f;

which works as intended when it comes to changing the direction that my skeleton animation faces.
That being said, when attaching another skeleton animation with BoneFollower, I get the following result:

Perhaps I am not using the correct way to change my skeleton animation?

Versions

  • Unity: 2021.3.25f1
  • spine-csharp Runtime: 4.1.0
  • spine-unity Runtime: 4.1.13
Related Discussions
...
  • Đã chỉnh sửa

@RogueWars Sorry to hear you're facing troubles. Your second image is almost accurate, just frame3 does not exist.

The problem is due to Unity's script update order. You seem to be calling skeletonAnimation.Skeleton.ScaleX *= -1 in e.g. an Update or LateUpdate call after the animation has been applied (and after callbacks UpdateLocal,UpdateWorld and UpdateComplete are done), but before BoneFollower.LateUpdate is called. This unfortunately leads to an incorrect state used by BoneFollower component, where the skeleton.ScaleX value is flipped but the bones are not yet updated accordingly (which happens in Bone.UpdateWorldTransform(), called at the end of SkeletonAnimation.Update()).

A solution would be to set Skeleton.ScaleX in Update() before any animation is applied by adding [DefaultExecutionOrder(-1)] to your component that sets Skeleton.ScaleX. This lets the script run before SkeletonAnimation. Another solution would be to set ScaleX after everything by calling it from LateUpdate() and setting the component's execution order to [DefaultExecutionOrder(1)]. In the second case you might be one frame late with your update however, so you might want to prefer the first solution.