signal animation_finished not working

Godot Version

4.4.1

Question

I’m a beginner and when I was making weapon manager in godot and I had a problem, the animation_finished signal didn’t work even though I did everything right.

here script

extends Node3D

@onready var anim = $AnimationPlayer
@onready var sound: AudioStreamPlayer3D = $AudioStreamPlayer3D

@export var damage :float

var can_shoot = false

func _ready() → void:
pass

func _process(delta: float) → void:
if Input.is_action_pressed(“shoot”) and can_shoot and not anim.is_playing():
anim.play(“shoot”)
sound.play()
can_shoot = false

func _on_animation_player_animation_finished(anim_name: StringName) → void:
if anim.name == (“shoot”):
can_shoot = true
elif anim.name == (“activate”):
can_shoot = true
elif anim.name == (“deactivate”):
can_shoot = false
visible = false

I think you opened the same topic twice by accident - can you close the other one please? signal animation_finished not working

In regards to your issue - did you connect the animation_finished signal to your _on_animation_player_animation_finished callback somewhere? I don’t see it anywhere in the code snippet you presented here.

Please also make sure to always paste code between three ticks ```

yes the signal is connected

Can you show how you did it then? Is it through code or inspector?

What happens if you add this line into your function? Is the animation name printed or nothing happens?

func _on_animation_player_animation_finished(anim_name: StringName) -> void:
    print(anim_name)

thank you so much, everything is working

1 Like

Oh, ok, I was not expecting this to fix your problem, but I’m happy you were able to figure it out :slight_smile:

I replaced my func with yours and everything started working.