Signal

A built-in type representing a signal of anObject.

Description

Signal is a built-inVariant type that represents a signal of anObject instance. Like allVariant types, it can be stored in variables and passed to functions. Signals allow all connectedCallables (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 anObject has a given signal name usingObject.has_signal().

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

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

Note

There are notable differences when using this API with C#. SeeC# API differences to GDScript for more information.

Tutorials

Constructors

Signal

Signal()

Signal

Signal(from:Signal)

Signal

Signal(object:Object, signal:StringName)

Methods

int

connect(callable:Callable, flags:int = 0)

void

disconnect(callable:Callable)

void

emit(...)varargconst

Array

get_connections()const

StringName

get_name()const

Object

get_object()const

int

get_object_id()const

bool

has_connections()const

bool

is_connected(callable:Callable)const

bool

is_null()const

Operators

bool

operator !=(right:Signal)

bool

operator ==(right:Signal)


Constructor Descriptions

SignalSignal()🔗

Constructs an emptySignal with no object nor signal name bound.


SignalSignal(from:Signal)

Constructs aSignal as a copy of the givenSignal.


SignalSignal(object:Object, signal:StringName)

Creates aSignal object referencing a signal namedsignal in the specifiedobject.


Method Descriptions

intconnect(callable:Callable, flags:int = 0)🔗

Connects this signal to the specifiedcallable. Optionalflags can be also added to configure the connection's behavior (seeConnectFlags constants). You can provide additional arguments to the connectedcallable by usingCallable.bind().

A signal can only be connected once to the sameCallable. If the signal is already connected, returns@GlobalScope.ERR_INVALID_PARAMETER and pushes an error message, unless the signal is connected withObject.CONNECT_REFERENCE_COUNTED. To prevent this, useis_connected() first to check for existing connections.

forbuttonin$Buttons.get_children():button.pressed.connect(_on_pressed.bind(button))func_on_pressed(button):print(button.name," was pressed")

voiddisconnect(callable:Callable)🔗

Disconnects this signal from the specifiedCallable. If the connection does not exist, generates an error. Useis_connected() to make sure that the connection exists.


voidemit(...)varargconst🔗

Emits this signal. AllCallables 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.


Arrayget_connections()const🔗

Returns anArray of connections for this signal. Each connection is represented as aDictionary that contains three entries:

  • signal is a reference to this signal;

  • callable is a reference to the connectedCallable;

  • flags is a combination ofConnectFlags.


StringNameget_name()const🔗

Returns the name of this signal.


Objectget_object()const🔗

Returns the object emitting this signal.


intget_object_id()const🔗

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


boolhas_connections()const🔗

Returnstrue if anyCallable is connected to this signal.


boolis_connected(callable:Callable)const🔗

Returnstrue if the specifiedCallable is connected to this signal.


boolis_null()const🔗

Returnstrue if thisSignal has no object and the signal name is empty. Equivalent tosignal==Signal().


Operator Descriptions

booloperator !=(right:Signal)🔗

Returnstrue if the signals do not share the same object and name.


booloperator ==(right:Signal)🔗

Returnstrue if both signals share the same object and name.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.