• Unity
  • animationState.Complete running twice?

  • संपादित
Related Discussions
...

Hi, I'm a bit confused here. I have the following events to keep track of animations:

private void Start() {
    ...some stuff before
    animationState.Start += OnAnimationStart;
    animationState.Complete += OnAnimationComplete;
    animationState.Interrupt += OnAnimationInterrupt;
}

private void OnAnimationStart(Spine.TrackEntry trackEntry) {
    if (trackEntry.Animation.Name == "attack-1") {
        Debug.Log("attack anim started");
    }
}

private void OnAnimationComplete(Spine.TrackEntry trackEntry) {
    if (trackEntry.Animation.Name == "attack-1") {
        Debug.Log("attack anim completed");
    }
}

private void OnAnimationInterrupt(Spine.TrackEntry trackEntry) {
    if (trackEntry.Animation.Name == "attack-1") {
        Debug.Log("attack anim interrupted");
    }
}

The code triggering the "attack-1" is just

animationState.SetAnimation(0, "attack-1", false);

No loop is involved.

The debug result is the following (code here and attached)

attack anim started
attack anim completed
attack anim completed
attack anim interrupted

why is complete running twice?

Complete should fire only once for a non-looping animation. The relevant code is here:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-csharp/src/AnimationState.cs#L596

The TrackEntry animationLast field in that code is set in AnimationState update. That means if you apply the AnimationState more than once without calling update, then you could have complete fire more than once. Other than that situation, or if you manually set animationLast, it should not be possible. You could breakpoint that line to see how it could possibly trigger. If you have an executable example, we can take a look.

Hi Nate. Thanks for you reply.
I didn't have the chance to take a look on the code again.
I will check it out when I have the time and test again based on your input.