• RuntimesUnity
  • How reliable are Spine events?

Hello.
I use Spine events to perform actions in my code. How reliable is this and will the event be triggered when the FPS drops?

Running events in my code is extremely important. Missing an event, for example if I forgot to add it to an animation, can lead to script bugs.

Can I compare the reliability of calling an event in an animation with calling code in a script, such as a coroutine? Even if the FPS drops, the code will be executed. What about events?

Example of my code

private void OnSpineEvent(TrackEntry trackEntry, Spine.Event e)
{
string spineEventName = e.Data.Name;
if (spineEventName == "DamageEvent") EnemyCharacterDealDamage();
}

private void OnSpineAnimationComplete(TrackEntry trackEntry)
{
if (currentAnimation == attack1Animation)
{
// End of attack animation.
enemyCharacterIsAttackPlayerNow = false;
}

Related Discussions
...

Spine events are generally reliable for triggering actions in your code, even when the FPS drops. The Spine runtime is designed to handle events accurately during animation playback. However, there are a few considerations to ensure the reliability of your events:

  1. Event Registration: Make sure you correctly register your event handlers. For example:

       skeletonAnimation.AnimationState.Event += OnSpineEvent;
       skeletonAnimation.AnimationState.Complete += OnSpineAnimationComplete;
  2. Event Presence: Ensure that the events are correctly set up in your Spine animations. Missing events in the animation setup can lead to missed triggers.

  3. Performance: While Spine events are reliable, extreme FPS drops can affect the timing of event handling. However, the events should still be fired, albeit with potential delays.

  4. Debugging: Use debugging tools to verify that events are being fired as expected. You can set breakpoints or use Debug.Log statements to monitor event triggers.

Here is an example of how you can handle events:

using UnityEngine;
using Spine.Unity;

public class HandleEvent : MonoBehaviour
{
    SkeletonAnimation skeletonAnimation;

    [SpineEvent]
    public string damageEventName;

    void Start () {
        skeletonAnimation = GetComponent<SkeletonAnimation>();
        skeletonAnimation.AnimationState.Event += OnSpineEvent;
        skeletonAnimation.AnimationState.Complete += OnSpineAnimationComplete;
    }

    private void OnSpineEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
        if (e.Data.Name == damageEventName) {
            EnemyCharacterDealDamage();
        }
    }

    private void OnSpineAnimationComplete (Spine.TrackEntry trackEntry) {
        if (currentAnimation == attack1Animation) {
            enemyCharacterIsAttackPlayerNow = false;
        }
    }

    private void EnemyCharacterDealDamage() {
        // Your damage logic here
    }
}

In summary, while Spine events are reliable, always ensure proper setup and registration. Extreme FPS drops might affect timing but should not prevent events from firing.

Events should never be missed, if you let the animation be updated and be applied (events happen in AnimationState apply, not update). Even if a frame drop so extreme that it is longer than the animation duration, it should work correctly. However, if it is crucial for you application, it may be worth checking.