Signals are similar to events in C#. They are a built-in implementation of the Observer Pattern.

Creating and connecting to signals

Waiting for signals to be fired

You can use the await keyword to continue execution until the specified signal is fired.

Simply reference the signal after using await

func change_scene(scene: String):
	$AnimationPlayer.play("fade_out")
	await $AnimationPlayer.animation_finished
	get_tree().change_scene_to_file(scene)

This codeblock waits for the AnimationPlayer’s animation_finished signal to fire until continuing execution.

Binding arguments to signals

You can pass in additional arguments that the signal emission does not pass, at connection time. You do this using Callable.bind().

Say you wanted to connect to the pressed signal of a bunch of buttons, but all those buttons need to have the same functionality, so it’s redundant to make a bunch of handler methods for each of them.

You could connect all of them to the same handler method, which would work, but say you also needed to know which button was pressed.

In this case, you would need to bind the button reference during connection.

Untitled

Lets store references to all the buttons using an exported array:

@export var button_array: Array[Button]

Untitled