• RuntimesUnity
  • Different track blending issue

Hi, I encountered the problem of character animations changing instantly when playing Spine animations on different tracks using Unity.

I am continuously looping the idle animation on track 0, and when I click on my character, I will play the select animation on track 1.

My character holds a shield in their right hand and hangs it next to their right foot. In idle animation, the shield floats up and down with character's breath, but in select animation it stays down. So when the shield floats above, clicking on the character will immediately cause the shield to appear below. What I expect is that when I click, the shield will still stays in its original position and slowly blend to the position where the two animations have been mixed. Simply put, it means changing more smoothly.

Is this possible?

Here is my code (nothing special):

public void Start()
{
        _skeleton.AnimationState.SetAnimation(0, idleAnimationName, true);
}
public void SetSelect()
{
        _skeleton.AnimationState.SetAnimation(1, selectAnimationName, false);
}

I know I can modify the blending result by setting TrackEntry.Alpha, but I think it only changes the degree how the select animation is blended into the idle animation, and cannot modify the smoothness when Track 1 starts playing the animation. The position of the shield will still change instantly in the first frame, just changes from 100% (alpha=1) down to 50% (alpha=0.5) down or less.

I have consulted the API's instructions on parameters such as mixBlendand mixDuration, and my understanding is that they only affect the blending effect when different animations are played on the same track, and do not affect the blending of animations on different tracks.

I checked the spine json file exported by my animation friend. In fact, the bones' positions of the shield were both modified in two animations. So I deleted position modifications in select animation and only kept the scale-changing part. After that, when I selected the character, the shield did not instantly switch positions and the animations changed smoothly. Is this the only way ?

    Related Discussions
    ...

    Misaki
    ahhhhh thank you !

    I tried that yesterday but in a wrong way, like this:

    public void Start()
    {
            _skeletonAnimation.AnimationState.SetEmptyAnimation(1, 0);
    }
    public void SetSelect()
    {
            _skeletonAnimation.AnimationState.SetAnimation(1, selectionAnimationName, false);
    }

    Seems like only using SetAnimation after SetEmptyAnimation can't make it mix from empty to itself, it only makes the skeleton plays select animation immediately.

    After reading the Guide i changed my code into this:

    public void Start()
    {
            // do nothing
    }
    public void SetSelect()
    {
            _skeletonAnimation.AnimationState.SetEmptyAnimation(1, 0);
            TrackEntry trackEntry = _skeletonAnimation.AnimationState.AddAnimation(1, selectionAnimationName, false, 0);
            trackEntry.MixDuration = 0.2f;
            trackEntry.Complete += OnSelectComplete;
    }
    private void OnSelectComplete(TrackEntry trackEntry)
    {
            trackEntry.SetEmptyAnimation(1, 0.2f);
            trackEntry.Complete -= OnSelectComplete;
    }

    And everything goes right. The character will smoothly blend into select animation when clicked. And when select animation completes, the character will also smoothly blend into idle (or any other animation is playing on track 0) animation.

    Thanks a lot <3 .

    Oh one more thing (and that's not a problem, only my casual little ps.):
    Since my select animation has not only scale changes but also other changes in bones (like translate), some animations will look like a bit not obvious when character is clicked. For example, in the attack animation, my character will raise the sword and cut it down. When the character is raising the sword, if i click him, the sword-holding hand will not continue raising up but slowly descend into the position where it is in select animation —— because track 1 is blending from empty into select animation.

    If that really bothers you, maybe delete other changes (like translate) in select animation and only leave the scale changes will help.