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 [Callable]s (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 [code]signal[/code] keyword. In C#, you may use the [code][Signal][/code] attribute on a delegate.
[codeblock]
[gdscript]
signal attacked
# Additional arguments may be declared.
# These arguments must be passed when the signal is emitted.
signal item_dropped(item_name, amount)
[/gdscript]
[csharp]
[Signal]
delegate void Attacked();
// Additional arguments may be declared.
// These arguments must be passed when the signal is emitted.
[Signal]
delegate void ItemDropped(itemName: string, amount: int);
[/csharp]
[/codeblock]
$DOCS_URL/getting_started/step_by_step/signals.html
$DOCS_URL/tutorials/scripting/gdscript/gdscript_basics.html#signals
Constructs an empty [Signal] with no object nor signal name bound.
Constructs a [Signal] as a copy of the given [Signal].
Creates a new [Signal] named [param signal] in the specified [param object].
Connects this signal to the specified [param callable]. Optional [param flags] can be also added to configure the connection's behavior (see [enum Object.ConnectFlags] constants). You can provide additional arguments to the connected [param callable] by using [method Callable.bind].
A signal can only be connected once to the same [Callable]. If the signal is already connected, returns [constant ERR_INVALID_PARAMETER] and pushes an error message, unless the signal is connected with [constant Object.CONNECT_REFERENCE_COUNTED]. To prevent this, use [method is_connected] first to check for existing connections.
[codeblock]
for button in $Buttons.get_children():
button.pressed.connect(_on_pressed.bind(button))
func _on_pressed(button):
print(button.name, " was pressed")
[/codeblock]
Disconnects this signal from the specified [Callable]. If the connection does not exist, generates an error. Use [method is_connected] to make sure that the connection exists.
Emits this signal. All [Callable]s 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.
Returns the list of [Callable]s connected to this signal.
Returns the name of this signal.
Returns the object emitting this signal.
Returns the ID of the object emitting this signal (see [method Object.get_instance_id]).
Returns [code]true[/code] if the specified [Callable] is connected to this signal.
Returns [code]true[/code] if the signal's name does not exist in its object, or the object is not valid.
Returns [code]true[/code] if the signals do not share the same object and name.
Returns [code]true[/code] if both signals share the same object and name.