abuki Yeah, I found it, just wanted to read some more detailed info how exactly the Layeredworks.
Note that you can also always hover over items longer or hit F1 to display the tooltip.
abuki Here is code for an isolated problem, see the last lines with TODO and comments. I would like to hear your thoughts on this?
Thanks for digging deeper! Your reproduction code can be simplified by removing anything on track 1:
using Spine;
using Spine.Unity;
using UnityEngine;
public class AnimationTest : MonoBehaviour
{
[SerializeField] private SkeletonAnimation skeletonAnimation;
[SerializeField] private AnimationReferenceAsset animWithKey; // animation with keyed bone
[SerializeField] private AnimationReferenceAsset animWithoutKey; // animation without keyed bone
private void Start () {
skeletonAnimation.AnimationState.SetAnimation(0, animWithKey, true);
skeletonAnimation.AnimationState.Start += AnimationStateOnStart;
}
private void Update () {
// remark: hit U, wait a bit and then hit T and observe the leftover applied keys of anim0WithKey
if (Input.GetKeyDown(KeyCode.U)) {
skeletonAnimation.AnimationState.SetAnimation(0, animWithKey, true);
}
if (Input.GetKeyDown(KeyCode.T)) {
var mainTrackEntry = skeletonAnimation.AnimationState.SetAnimation(0, animWithoutKey, true);
mainTrackEntry.MixDuration = 0; // 0.001f fixes the issue
}
}
private void AnimationStateOnStart (TrackEntry trackEntry) {
if (trackEntry.Animation == animWithoutKey.Animation) {
skeletonAnimation.Update(0); // TODO: This is causing the problem!
// When Update(0) is called, the bone stays in idleAnimation position where it was interrupted
// When Update(0) is not called, the bone mix to setup position as intended
// This behavior changed after spine runtime update
// Update(0) is here to prevent missing heads for one frame in some specific cases, but not sure if should be needed?
}
}
}
The problem seems to be due to skeletonAnimation.Update(0)
being called from the callback which is called from within AnimationState.SetAnimation
itself. While changing animation state from within callbacks must be done carefully (see this documentation section), we'll further investigate why exactly this is causing things to go wrong.
A quick fix BTW would be to set the mix duration to a tiny value other than 0 in the following line: mainTrackEntry.MixDuration = 0.001f;