Animation finished signal problem

Godot 4.3

I have many doors in my 3D scene that all share the same script. It contains door animation and interaction functionality. I use export variables to adjust the specifics of each door instance.
I would like to send a signal when each door animation has finished, but the editor only allows me to connect to a single door instance.
How do I send a signal to a script and every door using that script?
Note: each door has a slightly different animation length.

You can connect a signal from multiple doors to a single script in-editor. Could you share your scene tree and point out what you are trying to do? Could you further explain the big picture, what do you intend to do when a door animation finishes, or is it once every door animation is finished?

1 Like

Thanks. I got it to work using signals connected through code. That way the signal can connect to the AnimationPlayer used in each door scene.


# base script for all interactive doors

extends InteractiveItem

@export var mesh_action: String
@export var wait_time: = 1.0

@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var open_sound: AudioStreamPlayer3D = $OpenSound
@onready var close_sound: AudioStreamPlayer3D = $CloseSound

var closed: bool = true
var busy: bool = false # prevents spam actions

func _ready() -> void:
	animation_player.animation_finished.connect(_on_animation_player_animation_finished)
	closed = true

func action():
	if busy:
		return
	busy = true # block during animation
		
	if closed:
		open()
	else:
		close()
		
	closed = not closed # toggle state after calling functions
	
func open() -> void:
	animation_player.play(mesh_action)
	open_sound.play()
	
func close() -> void:
	animation_player.play_backwards(mesh_action)
	await get_tree().create_timer(wait_time).timeout
	close_sound.play()
	closed = true

func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if anim_name == mesh_action:
		busy = false