To ensure that the subsequent animation (anim2) does not interrupt the previous animation (anim1) and that anim1 always plays normally, you can use the AnimationState.AddAnimation()
method instead of SetAnimation()
. This method queues the animation to play after the current animation completes. Here is an example of how you can achieve this:
skeletonAnimation.state.SetAnimation(0, "anim1", false); // Play anim1
skeletonAnimation.state.AddAnimation(0, "anim2", false, 0); // Queue anim2 to play after anim1
If you need to interrupt the subsequent animation and ensure the previous animation plays normally, you can use the ClearTrack()
method to clear the track before setting the new animation:
skeletonAnimation.state.ClearTrack(0); // Clear any queued animations
skeletonAnimation.state.SetAnimation(0, "anim1", false); // Play anim1
Additionally, if you encounter issues with animations not playing correctly due to timing, you can manually update the animation state to ensure it is applied immediately:
skeletonAnimation.state.SetAnimation(0, "anim1", false);
skeletonAnimation.state.Update(0);
skeletonAnimation.state.Apply(skeletonAnimation.skeleton);
This ensures that the animation state is updated and applied in the same frame, preventing any unwanted frames from appearing.
For more detailed information, you can refer to the Spine Unity documentation on setting animations.