Answers for "create a signal godot"

2

godot signal

### Godot 3.x / GDScript 1
# signal declaration
signal signal_A
signal signal_B(param) # Optional; Parameter(s), cannot types hint

# To emit signal
emit("signal_A")
# Can pass parameter(s)
emit("signal_B", "variable")
# Can pass parameter(s) without declear at signal declaration
emit("signal_A", "var1", "var2", "var3")
# Can emit from other object
object.emit("signal_A")

# To connect signal; Return error if connect failed
connect("signal_A", self, "on_signal_A")
# Can connect from object and boardcast to other object
object.connect("signal_B", other, "on_signal_B")

# Received function need to accept all parameter(s)
func on_signal_A(a = "", b = "", c = ""):
	print(a + b + c)

# To check connection, parameters need to match connect ones; Return boolean
is_connect("signal_A", self, "on_signal_A")
object.is_connect("signal_B", other, "on_signal_B")

# To disconnect signal, parameters need to match connect ones; If object is free, signal will disconnect automatically
disconnect("signal_A", self, "on_signal_A")
object.disconnect("signal_B", other, "on_signal_B")
Posted by: Guest on July-02-2021
1

custom signal godot

extends Node2D


signal my_signal


func _ready():
    emit_signal("my_signal")
Posted by: Guest on August-04-2020

Browse Popular Code Answers by Language