Loading...
Loading...
Build event-driven, decoupled Godot 4.x gameplay with signals and node groups: declare and emit custom signals, connect with Callables (incl. bind/one-shot), and broadcast to many nodes via groups and call_group. Use when wiring node communication in a Godot project, replacing tight references with signals, emitting/connecting events, or porting 3.x connect("sig", self, "method") code.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills godot-signals-groupsgodot-gdscriptgodot-nodes-scenesgodot-nodes-scenesemit()sig.connect(_on_sig)CONNECT_ONE_SHOTbind()get_tree().get_nodes_in_group(...)call_group(...)is_connected()# coin.gd (reusable pickup — knows nothing about the player or HUD)
extends Area2D
signal collected(value: int)
func _on_body_entered(body: Node) -> void:
if body.is_in_group("player"):
collected.emit(10)
queue_free()# level.gd (the parent wires the coin to game state)
func _ready() -> void:
for coin in get_tree().get_nodes_in_group("coins"):
coin.collected.connect(_on_coin_collected)
func _on_coin_collected(value: int) -> void:
GameState.add_score(value)func _ready() -> void:
# Fire exactly once, then auto-disconnect.
$Door.opened.connect(_on_door_opened, CONNECT_ONE_SHOT)
# bind() appends arguments supplied at connect time (after the signal's own args).
$RedButton.pressed.connect(_on_button.bind("red"))
func _on_button(color: String) -> void:
print("Pressed the %s button" % color)func pause_all_enemies() -> void:
# Call a method on every node in the "enemies" group (no-op if missing).
get_tree().call_group("enemies", "set_paused", true)
func count_enemies() -> int:
return get_tree().get_nodes_in_group("enemies").size()func _ready() -> void:
add_to_group("enemies") # remove_from_group("enemies") to leavefunc open_chest() -> void:
$AnimationPlayer.play("open")
await $AnimationPlayer.animation_finished # pause until it emits
spawn_loot()connect("died", self, "_on_died")died.connect(_on_died)Object.connect("died", Callable(self, "_on_died"))_ready()if not sig.is_connected(cb): sig.connect(cb)call_groupreferences/signal-patterns.mdgodot-gdscriptawaitgodot-nodes-scenesgame-ai