• RuntimesGodot
  • Spine animation event not being detected in Godot 4.3

I'm trying to detect a Spine animation event in Godot 4.3, but the event callback is not being triggered.

Current Setup:

  1. In Spine, I've added an event named "attack" to my attack animation at a specific frame
  2. In Godot, I've connected the animation_event signal:
# In _ready()
spine_sprite.animation_event.connect(_on_animation_event)

# Event callback
func _on_animation_event(event_data) -> void:
    print("[Event Debug] ", event_data)  # Never prints anything
    if event_data and event_data.name == "attack":
        print("Attack event detected: ", event_data.name)
Related Discussions
...

To troubleshoot the issue of the Spine animation event not being detected in Godot 4.3, ensure the following:

  1. Signal Connection: Verify that the animation_event signal is correctly connected to the _on_animation_event function. Double-check the spelling and ensure that the connection is made after the SpineSprite node is fully initialized.

  2. Event Name: Confirm that the event name in Spine matches exactly with what you are checking in Godot. The event name is case-sensitive.

  3. Animation State: Ensure that the animation containing the event is being played on the SpineSprite. You can use the get_animation_state() method to verify the current animation.

  4. Debugging: Add additional debug prints to check if the signal connection is being made and if the animation is playing as expected.

Here's a refined version of your setup with additional debugging:

extends SpineSprite

func _ready():
    var animation_state = get_animation_state()
    animation_state.set_animation("attack", false, 0)
    spine_sprite.animation_event.connect(_on_animation_event)
    print("Signal connected and animation set.")

func _on_animation_event(event_data) -> void:
    print("[Event Debug] Event data received: ", event_data)
    if event_data and event_data.name == "attack":
        print("Attack event detected: ", event_data.name)

If the issue persists, consider checking if there are any updates or known issues with the spine-godot runtime for Godot 4.3 that might affect event handling.

I tried several approaches to detect the Spine animation event after the previous response, but still can't get it to work. Here's what I've tried:

  1. Checked the .skel file, and confirmed the "attack" event is properly defined in the animation data.

  2. Tried multiple event detection methods:

       # Method 1: Using animation_event signal
       if spine_sprite.has_signal("animation_event"):
           spine_sprite.connect("animation_event", _on_animation_event)
    
       # Method 2: Using event signal
       if spine_sprite.has_signal("event"):
           spine_sprite.connect("event", _on_spine_event)
    
       # Method 3: Using AnimationState events
       var animation_state = spine_sprite.get_animation_state()
       if animation_state:
           if animation_state.has_signal("animation_event"):
               animation_state.connect("animation_event", _on_animation_state_event)
           if animation_state.has_signal("event"):
               animation_state.connect("event", _on_animation_state_event)
    
       # Method 4: Using custom callback
       if animation_state and animation_state.has_method("set_event_listener"):
           animation_state.set_event_listener(func(track_entry, event): _on_spine_event_callback(track_entry, event))

    However, none of these approaches are detecting the event. The animation plays correctly, but the event callback is never triggered.

i think your issue is not having enough arguments in your callback function, it takes a SpineSprite, AnimationState, TrackEntry, and Event

5 dias depois

The way you connect to the event is correct. However, the signature (parameters) of your callback function is not. Have a look at our example:

EsotericSoftware/spine-runtimesblob/4.2/spine-godot/example-v4/examples/02-animation-state-listeners/animation-state-listeners.gd

If that issue persists, I'll need a minimal Godot project with your problematic asset and minimal code to reproduce the issue.