Class Signal
A built-in type representing a signal of an Object.
Remarks
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.
See Also
Constructors
Signal
Constructs an empty Signal with no object nor signal name bound.
Signal Signal
Signal(Signal)
Constructs a Signal as a copy of the given Signal.
Signal Signal(Signal from)
Parameters
fromSignal
Signal(Object, StringName)
Creates a Signal object referencing a signal named signal in the specified object.
Signal Signal(Object object, StringName signal)
Parameters
objectObjectsignalStringName
Methods
connect(Callable, int)
Connects this signal to the specified callable. Optional flags can be also added to configure the connection's behavior (see 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 @GlobalScope.ERR_INVALID_PARAMETER and pushes an error message, unless the signal is connected with Object.CONNECT_REFERENCE_COUNTED. To prevent this, use Signal.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")
int connect(Callable callable, int flags)
Parameters
disconnect(Callable)
Disconnects this signal from the specified Callable. If the connection does not exist, generates an error. Use Signal.is_connected to make sure that the connection exists.
void disconnect(Callable callable)
Parameters
callableCallable
emit(...)
Qualifiers: varargconst
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.
void emit(...)
get_connections
Qualifiers: const
Returns an Array of connections for this signal. Each connection is represented as a Dictionary that contains three entries:
signalis a reference to this signal;callableis a reference to the connected Callable;flagsis a combination of ConnectFlags.
Array get_connections
get_name
Qualifiers: const
Returns the name of this signal.
StringName get_name
get_object
Qualifiers: const
Returns the object emitting this signal.
Object get_object
get_object_id
Qualifiers: const
Returns the ID of the object emitting this signal (see get_instance_id).
int get_object_id
has_connections
Qualifiers: const
Returns true if any Callable is connected to this signal.
bool has_connections
is_connected(Callable)
Qualifiers: const
Returns true if the specified Callable is connected to this signal.
bool is_connected(Callable callable)
Parameters
callableCallable
is_null
Qualifiers: const
Returns true if this Signal has no object and the signal name is empty. Equivalent to signal == Signal().
bool is_null
Operators
!= (Signal)
Returns true if the signals do not share the same object and name.
bool != (Signal right)
Parameters
rightSignal
== (Signal)
Returns true if both signals share the same object and name.
bool == (Signal right)
Parameters
rightSignal