• RuntimesGodot
  • Check name _on_spine_sprite_animation_ended

I have connected the signal on_spine_sprite_animation_ended to my script in Godot, and it seems to work fine. However, I want to call the print() function only when the animation that has ended is the 'Side Attack' animation:

var current_entry = animation_state.get_current(0).get_animation().get_name()
func _on_spine_sprite_animation_ended(spine_sprite: Object, animation_state: Object, track_entry: Object) -> void:
	if current_entry == "Side Attack":
		print("Attack")

Currently, as I check the current animation, print() gets triggered at the beginning of 'Side Attack' rather than when it ends because it identifies the current animation instead of the one that has ended. Is there a way to check for the animation that has just ended, similar to how you can do with AnimatedSprite2D in Godot?"

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

    To achieve the desired behavior, you should check the animation name from the track_entry parameter in the _on_spine_sprite_animation_ended function. The track_entry parameter represents the animation that has just ended, allowing you to determine if it is the 'Side Attack' animation. Here's how you can modify your function:

    func _on_spine_sprite_animation_ended(spine_sprite: Object, animation_state: Object, track_entry: Object) -> void:
        var ended_animation_name = track_entry.get_animation().get_name()
        if ended_animation_name == "Side Attack":
            print("Attack")

    This way, the print() function will only be called when the 'Side Attack' animation has ended.

    AnonymousAd It may not be that the code is wrong, but that you misunderstood when an animation_ended event occurs. This event is not emitted simply because the animation has played to the last frame. It is the animation_completed event that is fired when the animation has played to the last frame. If the Side Attack animation has just finished playing without mixing out to an empty animation or playing another animation, this event will not be emitted. So I am assuming that you have mistakenly assumed that the event only occurs when the Side Attackanimation is set again.

    It may be helpful to watch the following video beginning at 8:23 for an explanation of when each event occurs: