To prevent an animation from mixing with others, you need to ensure that the higher track animation is applied without transitioning from or to any other animation. This can be achieved by setting the higher track animation directly without mixing from an empty animation. Here is an updated version of your script:
public void PlayBackOpeningLockerAnimation()
{
var currentAnimation = skeletonAnimation.AnimationState.GetCurrent(SpecialTrack);
if (currentAnimation == null)
{
// Directly set the animation on the special track without mixing from an empty animation
skeletonAnimation.AnimationState.SetAnimation(SpecialTrack, backOpeningLockerAnimation, false);
}
else
{
// Directly set the animation on the special track without mixing from an empty animation
skeletonAnimation.AnimationState.SetAnimation(SpecialTrack, backOpeningLockerAnimation, false);
}
// Optionally add an empty animation after back-opening-locker animation to avoid freeze frame
skeletonAnimation.AnimationState.AddEmptyAnimation(SpecialTrack, 0.2f, 0f);
}
By setting the animation directly on the special track without using SetEmptyAnimation
, you ensure that the animation is applied fully and immediately, without mixing with the idle animation or any other animations on lower tracks.
For more details, you can refer to the Spine Runtimes Guide on Empty Animations.