You are reading the
(unstable) version of this documentation, which may document features not available
or compatible with Godot 3.x.
Checking the stable version of the documentation...
Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page are up to date. If you can still find outdated information, please open an issue.
Built-in type representing a signal defined in 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.
In GDScript, signals can be declared with the
signal keyword. In C#, you may use the
[Signal] attribute on a delegate.
signal attacked # Additional arguments may be declared. # These arguments must be passed when the signal is emitted. signal item_dropped(item_name, amount)
[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);
Signal ( )
Signal ( Object object, StringName signal )
disconnect ( Callable callable )
emit ( ... ) vararg const
get_connections ( ) const
get_name ( ) const
get_object ( ) const
get_object_id ( ) const
is_connected ( Callable callable ) const
is_null ( ) const
operator != ( Signal right )
operator == ( Signal right )
Signal Signal ( )
Constructs an empty Signal with no object nor signal name bound.
Constructs a Signal as a copy of the given Signal.
Signal Signal ( Object object, StringName signal )
Creates a new Signal named
signal in the specified
int connect ( Callable callable, int flags=0 )
Connects this signal to the specified
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 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")
void disconnect ( Callable callable )
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.
void emit ( ... ) vararg const
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.
Array get_connections ( ) 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.
StringName get_name ( ) const
Returns the name of this signal.
Object get_object ( ) const
Returns the object emitting this signal.
int get_object_id ( ) const
Returns the ID of the object emitting this signal (see Object.get_instance_id).
bool is_connected ( Callable callable ) const
true if the specified Callable is connected to this signal.
bool is_null ( ) const
true if the signal's name does not exist in its object, or the object is not valid.
bool operator != ( Signal right )
true if the signals do not share the same object and name.
bool operator == ( Signal right )
true if both signals share the same object and name.