Click or drag to resize

ObjectConnect Method

Connects a signal to a method on a target object. Pass optional binds to the call as an Array of parameters. These parameters will be passed to the method after any parameter used in the call to EmitSignal(String, Object). Use flags to set deferred or one-shot connections. See ObjectConnectFlags constants.

A signal can only be connected once to a method. It will throw an error if already connected, unless the signal was connected with . To avoid this, first, use IsConnected(String, Object, String) to check for existing connections.

If the target is destroyed in the game's lifecycle, the connection will be lost.

Examples:

connect("pressed", self, "_on_Button_pressed") # BaseButton signal
connect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signal
connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal

An example of the relationship between binds passed to Connect(String, Object, String, Array, UInt32) and parameters used when calling EmitSignal(String, Object):

connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed last
emit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed first
func _on_Player_hit(hit_by, level, weapon_type, damage):
    print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])

Namespace:  Godot
Assembly:  GodotSharp (in GodotSharp.dll) Version: 1.0.0
Syntax
C#
public Error Connect(
	string signal,
	Object target,
	string method,
	Array binds = null,
	uint flags = 0
)

Parameters

signal
Type: SystemString

[Missing <param name="signal"/> documentation for "M:Godot.Object.Connect(System.String,Godot.Object,System.String,Godot.Collections.Array,System.UInt32)"]

target
Type: GodotObject

[Missing <param name="target"/> documentation for "M:Godot.Object.Connect(System.String,Godot.Object,System.String,Godot.Collections.Array,System.UInt32)"]

method
Type: SystemString

[Missing <param name="method"/> documentation for "M:Godot.Object.Connect(System.String,Godot.Object,System.String,Godot.Collections.Array,System.UInt32)"]

binds (Optional)
Type: Godot.CollectionsArray
If the parameter is null, then the default value is new Godot.Collections.Array {}
flags (Optional)
Type: SystemUInt32

[Missing <param name="flags"/> documentation for "M:Godot.Object.Connect(System.String,Godot.Object,System.String,Godot.Collections.Array,System.UInt32)"]

Return Value

Type: Error

[Missing <returns> documentation for "M:Godot.Object.Connect(System.String,Godot.Object,System.String,Godot.Collections.Array,System.UInt32)"]

See Also