Hi,

I'm having issues with checking for events in Godot.

At the moment, in my "Attack" animation, there's an event keyed with a string "Attack" I am trying to call a function every time this gets called:

@onready var Sprite = get_node("SpineSprite")
if Sprite.get_data().get_event_name() == "Attack" and distance_to_target <= attack_range:
if target.is_in_group("enemy") or target.is_in_group("breakable"):
player_velocity = velocity
target.hit(damageplayer, player_velocity)

At the moment this is just breaking the game with this error showing up:
Invalid call. Nonexistent function 'get_data' in base 'SpineSprite (spine_sprite.gd)'.

I'd really appreciate any help!

Related Discussions
...

Spinebot Hi I am getting this error:
Invalid call. Nonexistent function 'get_data' in base 'SpineSprite (spine_sprite.gd)'.

I am not sure if I get this entirely, since the event is "Attack", would it be?:
Sprite.connect("Attack", self, "_on_animation_event")

Then in this function is track_index = 0 and event "Attack" again since that is the event and track on which I am playing all the animations on?:

func _on_animation_event(0, "Attack"):

When I do this I get this error:

Line 388:Expected parameter name.

I have been struggling with this for quite a while. I have implemented an answer from my previous discussion and tried different variants and nothing seems to work.

Right now I'm at a point where at least the game doesn't break with a critical error, but Godot doesn't seem to be detecting any events at all. This is what I currently have:

@onready var Sprite = get_node("SpineSprite")

func _ready():
	Sprite.get_animation_state().set_animation("Front idle not possessed", true, 0)
	Sprite.connect("animation_event", Callable(self, "_on_animation_event"))

func _physics_process(delta: float) -> void:
	if lastangle >= -0.392 and lastangle < 0.392:  # Right (0° to 45°)
			is_looping = false
			new_animation = "Side Attack no possessed"
			new_scale_x = 0.4
			attack_timer = false
			$"Can Attack".start()

	if current_entry == null or current_entry != new_animation:
		Sprite.get_animation_state().set_animation(new_animation, is_looping, 0)
		Sprite.scale.x = new_scale_x

func _on_animation_event(track_index, event):
	print("event called")
	#and distance_to_target <= attack_range
	#if event.string_value == "Attack":
	if target.is_in_group("enemy") or target.is_in_group("breakable"):
		player_velocity = velocity
		target.hit(damageplayer, player_velocity)	

The animation is playing so I know for a fact the events should be called, but not even the _on_animation_event function is getting called as the print statement is not getting called either.

Can someone help me please?

  • Misaki님이 이에 답장했습니다.

    It seems like you are trying to connect and handle animation events in Godot using the spine-godot runtime, but the _on_animation_event function is not being triggered. Here are a few things you can check to troubleshoot the issue:

    1. Ensure Events are Defined in Spine: Make sure that the animation you are playing has events defined in the Spine editor. Without events, the animation_event signal will not be emitted.

    2. Correct Signal Connection: Double-check that the signal connection is correct. You are using Sprite.connect("animation_event", Callable(self, "_on_animation_event")), which should work if Sprite is indeed the SpineSprite node and the signal name is correct.

    3. Check Node Path: Verify that the path "SpineSprite" is correct and that it points to the actual SpineSprite node in your scene.

    4. Signal Emission: Ensure that the SpineSprite node is emitting the animation_event signal. You can add a debug print statement in the signal connection line to confirm that the connection is being made.

    5. Event Handling Logic: Make sure that the logic inside _on_animation_event is not causing any issues. For debugging, you can simplify the function to just print the event details to ensure it is being called.

    Here's a simplified version of your code for debugging:

    @onready var Sprite = get_node("SpineSprite")
    
    func _ready():
        Sprite.get_animation_state().set_animation("Front idle not possessed", true, 0)
        Sprite.connect("animation_event", Callable(self, "_on_animation_event"))
    
    func _on_animation_event(track_index, event):
        print("Event called: ", event.data.name)

    If the print statement in _on_animation_event is still not being called, the issue might be with the event setup in Spine or the signal connection. Double-check these areas to ensure everything is set up correctly.

    Merged 3 posts from Checking for event in Godot..

    AnonymousAd I can understand you wanting to start a new thread since Spinebot only replied to your first reply, but if the issue is not resolved, someone from the Spine team will eventually reply, so I would appreciate it if you could continue the same topic in the same thread.

    As Spinebot suggested, I also think you should try testing with a short, simple code first for debugging. First, check to see if the following code will work:

    @onready var Sprite = $SpineSprite
    
    func _ready() -> void:
    	var animation_state = Sprite.get_animation_state()
    	animation_state.set_animation("Side Attack no possessed", false, 0)
    	Sprite.animation_event.connect(_on_animation_event)
    
    func _on_animation_event(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry, event: SpineEvent):
    	print("Animation event: " + track_entry.get_animation().get_name() + ", " + event.get_data().get_event_name())
    	if (event.get_data().get_event_name() == "Attack"):		
    		print("hit")

      Misaki Thank you! That solved it.