Howdy!
I have an interesting issue. My code is setup in such a way that the next animation will not play until the current one is finished.
However, sometimes (and I cannot reproduce this reliably) an animation finishes near instantly.
My current animations take about 0.5-2 seconds, however I am getting a complete callback (sometimes) after a few milliseconds.
Here is a log example of the bad timing (its completing after a few milliseconds):
[Log] Started Animation attackMainWeapon timestamp: 17.28275
[Log] Animation Complete: attackMainWeapon timestamp: 17.36266
Here is a good log example of good complete callback finishing (it completes after the full animation)
[Log] Started Animation attackMainWeapon timestamp: 14.98926
[Log] Animation Complete: attackMainWeapon timestamp: 15.66332
Here is my custom code for setting up the completion callback, if you see anything please let me know (I would GREATLY appreciate a hint as to what I might have done wrong here).
public class UnitAnimator : MonoBehaviour
{
public AnimationCompleteCallback animationCompleteCallback;
protected AnimationStateData _animationStateData;
protected SkeletonAnimation _animator;
protected Spine.AnimationState _baseState;
private S_EffectEvent _data;
private string _currentAnimation;
public void Start()
{
_animator = GetComponentInChildren<SkeletonAnimation>();
_baseState = _animator.state;
_baseState.Complete += delegate (TrackEntry entry)
{
AnimationComplete();
};
}
public void AnimationComplete()
{
if (_data == null)
{
return;
}
Debug.Log("Animation Complete: " + _currentAnimation + Time.time);
_data.activeAnimationObjects.Remove(gameObject);
}
public void PlayAnimation(string t_unitAnimation, bool loop, S_EffectEvent data = null)
{
_currentAnimation = t_unitAnimation;
Debug.Log("Started Animation " + t_unitAnimation + Time.time);
if (data != null)
{
_data = data;
_data.activeAnimationObjects.Add(gameObject);
}
_baseState.SetAnimation(0, t_unitAnimation, loop);
}
}