Skip to reading
GDScript Programming & Godot

29. Custom events and Godot signals

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func on_custom_event(event: Dictionary = {}) -> void:
    if str(event.get("reason", "")) == "signal_powered":
        Log("The lamp has power.")
Code example
func run() -> void:
    await EmitEvent("OnCustomEvent", {"reason": "signal_powered"})

This uses the standard OnCustomEvent route and a reason field. A custom exact event name is also possible, but a native handler needs a route that maps to a real method. For a shared native listener, the standard hook plus a discriminator is straightforward.

Godot signals are a different mechanism: a particular object emits a typed signal to connected Callables. Use PCA events for adventure-wide notifications and Godot signals for relationships between your own nodes. The Godot signal chapter shows the full connection pattern.

Do not broadcast the same notification from its own handler without a guard. Set saved state before emitting a completion event, and avoid circular chains of listeners.

Page 38 of 378Permalink
Go to page