Inheritance #

Signal




Table of contents

Signal #

builtin_classes

A built-in type representing a signal of an Object.

Signal is a built-in Variant type that represents a signal of an Object instance. Like all Variant types, it can be stored in variables and passed to functions. Signals allow all connected Callables (and by extension their respective objects) to listen and react to events, without directly referencing one another. This keeps the code flexible and easier to manage. You can check whether an Object has a given signal name using Object.has_signal.

In GDScript, signals can be declared with the signal keyword. In C#, you may use the Signal attribute on a delegate.

GDScript

signal attacked

# Additional arguments may be declared.
# These arguments must be passed when the signal is emitted.
signal item_dropped(item_name, amount)

C#

[Signal]
delegate void AttackedEventHandler();

// Additional arguments may be declared.
// These arguments must be passed when the signal is emitted.
[Signal]
delegate void ItemDroppedEventHandler(string itemName, int amount);

Members #

Methods #

func connect(flags: int = 0) -> int#

Connects this signal to the specified callable. Optional flags can be also added to configure the connection's behavior (see Object.ConnectFlags constants). You can provide additional arguments to the connected callable by using Callable.bind.

A signal can only be connected once to the same Callable. If the signal is already connected, returns ERR_INVALID_PARAMETER and pushes an error message, unless the signal is connected with Object.CONNECT_REFERENCE_COUNTED. To prevent this, use is_connected first to check for existing connections.

for button in $Buttons.get_children():
    button.pressed.connect(_on_pressed.bind(button))

func _on_pressed(button):
    print(button.name, " was pressed")

func disconnect(callable: Callable) -> void#

Disconnects this signal from the specified Callable. If the connection does not exist, generates an error. Use is_connected to make sure that the connection exists.

vararg const func emit() -> void#

Emits this signal. All Callables connected to this signal will be triggered. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.

const func get_connections() -> Array#

Returns an Array of connections for this signal. Each connection is represented as a Dictionary that contains three entries:

- signal is a reference to this signal;

- callable is a reference to the connected Callable;

- flags is a combination of Object.ConnectFlags.

const func get_name() -> StringName#

Returns the name of this signal.

const func get_object() -> Object#

Returns the object emitting this signal.

const func get_object_id() -> int#

Returns the ID of the object emitting this signal (see Object.get_instance_id).

const func has_connections() -> bool#

Returns true if any Callable is connected to this signal.

const func is_connected(callable: Callable) -> bool#

Returns true if the specified Callable is connected to this signal.

const func is_null() -> bool#

Returns true if this Signal has no object and the signal name is empty. Equivalent to signal == Signal().

Annotations #

Constants #

Constructors #

Signal() -> Signal #

Constructs an empty Signal with no object nor signal name bound.

Signal(from: Signal) -> Signal #

Constructs a Signal as a copy of the given Signal.

Signal(signal: StringName) -> Signal #

Creates a Signal object referencing a signal named signal in the specified object.

Enums #

Operators #

Signal != Signal -> bool#

Returns true if the signals do not share the same object and name.

Signal == Signal -> bool#

Returns true if both signals share the same object and name.

Signals #

Theme Items #

Tutorials #