• RuntimesUnity
  • Prevent an animation from mixing with others

  • Изменено

Hi,

I've created my Player prefab (using Unity + Adventure Creator) with Spine animation and I'm trying to ensure that certain animations do not get mixed with others. To achieve this, I came up with a script that plays specific animations on a higher track index.

Here's the script I'm using:

public void PlayBackOpeningLockerAnimation()
{
    var currentAnimation = skeletonAnimation.AnimationState.GetCurrent(SpecialTrack);

    if (currentAnimation == null)
    {
        skeletonAnimation.AnimationState.SetEmptyAnimation(SpecialTrack, 0.2f);
        skeletonAnimation.AnimationState.AddAnimation(SpecialTrack, backOpeningLockerAnimation, false, 0);
    }
    else
    {
        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);
}

However, this script still mixes the animation on the special track with the idle animation.
Did I miss anything here? Thank you for your help.

Related Discussions
...

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.

  • Misaki ответили на это сообщение.
    • Изменено

    Spinebot Is the idle animation playing on track 0? If you want to apply only the pose from the animation on SpecialTrack while playing the idle animation, you can set the idle animation to track 1 or higher and set the idle animation's TrackEntry.Alpha to 0 so that the idle animation remains set but the idle animation pose is not applied to the skeleton.
    If it is okay to just stop the idle animation from playing, set an empty animation on the track where the idle animation is playing and mix it out when setting the animation to the SpecialTrack.
    Tracks are basically used to blend with the animation of the lower track, so if you simply want to replace the animation with another one, the general approach is to set the new animation to the track where the animation is already playing. However, if you want the animation playing on the higher track to be 100% reflected in the skeleton pose for some reasons, you can use the approaches described above.

    Yes, the idle animation is playing on track 0.
    Thanks a lot for your quick response. I didn't know about that. I'll give it a try!