The problem with your code was that it first clears the track, then there is no active track left as a solid base to add the alpha-blended new track to. So it adds 10% of your new animation to the previous frame state.
I have fixed your code, using the UpdateLocal
callback method you can be sure that your code gets called after the other animations have been applied, so there is no need to call ClearTracks()
:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using Spine;
public class AnimController : MonoBehaviour
{
public AnimationReferenceAsset otherAnimation;
SkeletonAnimation skeletonAnimation;
Spine.Skeleton skeleton;
Spine.AnimationState spineAnimationState;
bool mixing = false;
public float easedTime;
void Start()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
spineAnimationState = skeletonAnimation.AnimationState;
spineAnimationState.SetAnimation(0, "animation", true);
skeletonAnimation.UpdateLocal += OnUpdateLocal;
Invoke("makeTransitionToOtherAnimation", 3);
}
void makeTransitionToOtherAnimation()
{
//spineAnimationState.ClearTracks(); // no need to clear tracks, unless you really want to.
mixing = true;
}
void OnUpdateLocal(ISkeletonAnimation animated)
{
if (mixing)
{
//skeleton.SetBonesToSetupPose(); // if you cleared the tracks, this line would be necessary to base any blending on the setup pose, otherwise you have the previous frame state as a base.
otherAnimation.Animation.Apply(skeleton, 0, 1, false, null, easedTime, MixBlend.Replace, MixDirection.In);
}
}
}