overview:
I'm relying on Complete and Interrupt events to setup/clear some variables after a non looping "attack" animation.
what's happening
After hitting the button in random intervals or holding the button, sometimes the animation gets stuck in the last frame, no events are getting fired and I can't clear the variables on my callbacks. Shouldn't Complete, End or Dispose run on this situation? I mean, even if I keep holding the button, and the animation have ended, aren't they supposed to trigger? User holds attack, character attacks, then goes to idle state (after using the callbacks) etc.
My general code below. I can't generate a working code to test without disclosing atm.
private void OnAnimationComplete(Spine.TrackEntry trackEntry) {
if (trackEntry.Animation.Name == "attack") {
onAttackBehavior = false;
animationBasicAttack = false;
Debug.Log("attack anim completed");
}
}
private void OnAnimationInterrupt(Spine.TrackEntry trackEntry) {
if (trackEntry.Animation.Name == "attack") {
onAttackBehavior = false;
animationBasicAttack = false;
Debug.Log("attack anim interrupted");
}
}
...
private void SetAnimations() {
// animations don't run here. It's only to set the state based on user input and character conditions
// onAttackBehavior and animationBasicAttack are used to define the state here.
// but they are never released on callbacks above. Then I get stuck on the same state always and playing the same animation (stuck on last frame)
}
private void ApplyAnimations() {
if (previousState != state) {
if(state == BodyState.Attack) {
// this case is running only once, which is fine and desired
skeleton.SetSkin("whatever");
skeleton.SetSlotsToSetupPose();
animationState.Apply(skeleton);
animationState.SetAnimation(0, "attack", false);
} else if (...) // bunch of other animation states being applied
} else {
// This line keeps running when the attack animation gets stuck in the last frame.
Debug.Log("keep playing the old animation: " + previousState);
}
previousState = state;
}