godot-signal-architecture

$npx mdskill add thedivergentai/GD-Agentic-Skills/godot-signal-architecture

Implements signal-driven architecture using Signal Up/Call Down pattern for loose coupling.

  • Decouples nodes by using signals for upward communication and direct calls downward.
  • Depends on Godot 4.7+ typed signals, connect flags, and AutoLoad event buses.
  • Recommends typed signals over string-based connect to prevent silent failures.
  • Delivers expert patterns for signal chains, one-shot connections, and scoped buses.

SKILL.md

.github/skills/godot-signal-architectureView on GitHub ↗
---
name: godot-signal-architecture
description: "Expert blueprint for signal-driven architecture using \"Signal Up, Call Down\" pattern for loose coupling. Covers typed signals, signal chains, one-shot connections, and AutoLoad event buses. Use when implementing event systems OR decoupling nodes. Keywords signal, emit, connect, CONNECT_ONE_SHOT, CONNECT_REFERENCE_COUNTED, event bus, AutoLoad, decoupling."
---

## Godot 4.7 Baseline

- Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18).
- Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6.
- **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes.

# Signal Architecture

Signal Up/Call Down, typed signals, and scoped buses — not connect/emit tutorials.

## NEVER Do in Signal Architecture

- **NEVER use the legacy string-based `Object.connect()`** — Typos result in silent failures. Always use `signal.connect(_callback)` for compile-time validation.
- **NEVER use signals to dictate behavior top-down** — Signals are past-tense events (e.g., "died"). Use direct method calls for commands (e.g., "kill").
- **NEVER connect a signal twice to the same Callable** — This throws an `ERR_INVALID_PARAMETER` at runtime unless using the `Object.CONNECT_REFERENCE_COUNTED` flag to stack connections.
- **NEVER use a Global Signal Bus for local data** — Pollutes global state and makes debugging harder. Use local connections for scene-specific logic.
- **NEVER assume callbacks must accept all signal arguments** — Use `unbind()` to drop unwanted parameters and keep your API clean.
- **NEVER create circular signal dependencies** — A signals B, B signals back to A? Use a mediator (parent or AutoLoad) to break the loop.
- **NEVER skip signal typing** — `signal moved` without types lacks editor support. Always use `signal moved(dir: Vector2)`.
- **NEVER forget to disconnect dynamic signals** — Ghost connections cause "call on null instance" errors. Disconnect in `_exit_tree()` or when retargeting ([disconnect_ghost_signals.gd](scripts/disconnect_ghost_signals.gd)).
- **NEVER emit signals with immediate side effects on the emitter** — If `died.emit()` calls `queue_free()`, listeners might fail to respond. Emit first.
- **NEVER use signals for high-frequency data streams** — Sending 1000+ signals/second (like per-particle updates) is inefficient. Use shared arrays or direct buffers.

---

## Signal Up / Call Down

- **Children → parents:** past-tense signals (`health_changed`, `died`).
- **Parents → children:** direct calls / properties (`apply_damage`, `play_anim`).
- **Siblings:** parent mediator or carefully scoped Autoload bus — never sibling hard refs.

**Use signals for:** UI presses, death → game over, loot → inventory, cross-scene bus events.
**Use direct calls for:** parent commanding child, local property access.

## Decision Tree: Where to Connect

| Scope | Pattern | MANDATORY script |
|-------|---------|------------------|
| Child notifies parent / UI | Local `signal.connect` in parent `_ready` | [signal_up_call_down_pattern.gd](scripts/signal_up_call_down_pattern.gd) |
| Parent orchestrates children | Method calls down (not signals) | same |
| Cross-scene / systems (achievements, save) | Autoload bus | [global_signal_bus_router.gd](scripts/global_signal_bus_router.gd) / [global_event_bus.gd](scripts/global_event_bus.gd) |
| Linear async steps (load → fade → spawn) | `await` signal sequence | [await_signal_sequencing.gd](scripts/await_signal_sequencing.gd) / [complex_signal_sequencer.gd](scripts/complex_signal_sequencer.gd) |
| Retarget tracking (new enemy) | Disconnect old first | [disconnect_ghost_signals.gd](scripts/disconnect_ghost_signals.gd) |
| One-shot / physics-safe | `CONNECT_ONE_SHOT` / `CONNECT_DEFERRED` | [one_shot_deferred_connections.gd](scripts/one_shot_deferred_connections.gd) |
| Extra context / drop args | `Callable.bind` / `unbind` | [callable_bind_context.gd](scripts/callable_bind_context.gd) / [unbind_unwanted_args.gd](scripts/unbind_unwanted_args.gd) |

## Available Scripts

- [signal_up_call_down_pattern.gd](scripts/signal_up_call_down_pattern.gd) — **MANDATORY** before hierarchy wiring.
- [global_signal_bus_router.gd](scripts/global_signal_bus_router.gd) / [global_event_bus.gd](scripts/global_event_bus.gd) — **MANDATORY** before Autoload buses.
- [disconnect_ghost_signals.gd](scripts/disconnect_ghost_signals.gd) — **MANDATORY** when switching tracked emitters.
- [await_signal_sequencing.gd](scripts/await_signal_sequencing.gd) / [complex_signal_sequencer.gd](scripts/complex_signal_sequencer.gd) — **MANDATORY** for multi-step awaits.
- [safe_dynamic_connections.gd](scripts/safe_dynamic_connections.gd) — `is_connected` guards.
- [one_shot_deferred_connections.gd](scripts/one_shot_deferred_connections.gd) — one-shot / deferred flags.
- [callable_bind_context.gd](scripts/callable_bind_context.gd) / [unbind_unwanted_args.gd](scripts/unbind_unwanted_args.gd) — bind/unbind.
- [track_signal_emitter_source.gd](scripts/track_signal_emitter_source.gd) — `CONNECT_APPEND_SOURCE_OBJECT`.
- [signal_debugger.gd](scripts/signal_debugger.gd) / [signal_spy.gd](scripts/signal_spy.gd) — debug / test spies.

## Lambda Capture Cleanup (complete)

Godot auto-disconnects most connections when a node frees. **Exception:** lambdas that capture locals — you must disconnect manually.

```gdscript
var my_lambda: Callable

func _ready() -> void:
    var x := 10
    my_lambda = func(): print(x)
    player.died.connect(my_lambda)

func _exit_tree() -> void:
    if player and player.died.is_connected(my_lambda):
        player.died.disconnect(my_lambda)
```

Prefer named methods or [disconnect_ghost_signals.gd](scripts/disconnect_ghost_signals.gd) when retargeting.

## CONNECT_REFERENCE_COUNTED — Correct Semantics

`CONNECT_REFERENCE_COUNTED` means **multiple identical connects share one connection with a refcount** (connect N times / disconnect N times). It is **not** "auto-cleanup when the emitter frees" and does **not** fix capturing-lambda leaks.

- Auto-cleanup on free: normal connections to Object methods (non-capturing) are cleared when either side is freed.
- Capturing lambdas: always manual `disconnect` (see above).
- One-shot auto-remove after fire: `CONNECT_ONE_SHOT`.


## Deep recipes (on demand)

> LLM-ignorance rule: if a general agent would not know it before reading, it lives here or in `scripts/` — never delete, only move.

| Topic | Reference |
|-------|-----------|
| Patterns 1–7 + gotchas | [implementation-patterns.md](references/implementation-patterns.md) |

## Reference

> Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain — do not preload the whole lattice.

### Official Documentation
- [Using signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html) — Core emit/connect model and why signals decouple nodes without hard references.
- [Scene organization](https://docs.godotengine.org/en/stable/tutorials/best_practices/scene_organization.html) — Canonical “signal up, call down” ownership rules that keep parent→child command flows explicit.
- [Instancing with signals](https://docs.godotengine.org/en/stable/tutorials/scripting/instancing_with_signals.html) — Emit from spawned scenes so parents/managers receive bullets, loot, and other products without fixed node paths.
- [Autoloads versus regular nodes](https://docs.godotengine.org/en/stable/tutorials/best_practices/autoloads_versus_regular_nodes.html) — When a global EventBus is justified vs when scene-local signal wiring is safer.
- [Singletons (Autoload)](https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html) — How to register a typed signal bus that survives scene changes.
- [Signal](https://docs.godotengine.org/en/stable/classes/class_signal.html) — Typed `Signal` API: `emit`, `connect`, `is_connected`, and disconnect helpers used throughout this skill.
- [Callable](https://docs.godotengine.org/en/stable/classes/class_callable.html) — `bind()` / `unbind()` for injecting or discarding callback context without wrapper lambdas.
- [Object](https://docs.godotengine.org/en/stable/classes/class_object.html) — `CONNECT_ONE_SHOT`, `CONNECT_DEFERRED`, `CONNECT_REFERENCE_COUNTED`, and `CONNECT_APPEND_SOURCE_OBJECT` flags.
- [GDScript basics](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html) — Typed `signal` declarations and `await` on signals for linear async sequences.
- [Using SceneTree](https://docs.godotengine.org/en/stable/tutorials/scripting/scene_tree.html) — Connection lifetime across enter/exit tree and why dynamic listeners must disconnect when retargeting.
- [Godot notifications](https://docs.godotengine.org/en/stable/tutorials/best_practices/godot_notifications.html) — Safe connection timing relative to `_ready`, parent caches, and user signals.
- [Idle and Physics Processing](https://docs.godotengine.org/en/stable/tutorials/scripting/idle_and_physics_processing.html) — Why deferred signal handlers matter when callbacks mutate physics bodies mid-step.

### Related Skills

#### Prerequisites
- [godot-project-foundations](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-project-foundations/SKILL.md) — Project layout, Autoload registration, and scene ownership conventions signals plug into.
- [godot-gdscript-mastery](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-gdscript-mastery/SKILL.md) — Typed Callables, `await`, and signal syntax required before advanced connect flags and sequencers.
- [godot-autoload-architecture](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-autoload-architecture/SKILL.md) — Singleton boot order and ownership rules for global EventBus routers (not for local scene events).

#### Complements
- [godot-composition](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-composition/SKILL.md) — Component nodes emit past-tense events; parents compose by connecting those signals and calling down.
- [godot-scene-management](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-scene-management/SKILL.md) — Scene swaps and loaders must reconnect or re-emit through buses without ghost listeners.
- [godot-state-machine-advanced](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-state-machine-advanced/SKILL.md) — State enter/exit often drives signal fan-out; keeps FSM transitions from becoming circular signal graphs.
- [godot-resource-data-patterns](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-resource-data-patterns/SKILL.md) — Prefer Resources for shared config; signals carry change events, not duplicated mutable state blobs.
- [godot-testing-patterns](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-testing-patterns/SKILL.md) — `watch_signals` / spies pair with this skill’s emit contracts for unit and integration tests.
- [godot-ui-containers](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-ui-containers/SKILL.md) — Buttons and menus should signal intent upward; controllers call down to update Control trees.

#### Downstream / consumers
- [godot-dialogue-system](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-dialogue-system/SKILL.md) — Line/choice completion events should follow signal-up orchestration into UI and quest listeners.
- [godot-ability-system](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-ability-system/SKILL.md) — Cooldown, cast, and hit payloads need typed signals so HUD/VFX stay decoupled from ability nodes.
- [godot-combat-system](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-combat-system/SKILL.md) — Damage/death/score chains are the classic signal-up fan-out into UI, audio, and progression.
- [godot-performance-optimization](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-performance-optimization/SKILL.md) — Escalate when high-frequency emit storms show up; replace per-tick signals with buffers or direct reads.

#### Master
- [godot-master](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-master/SKILL.md) — Library router and mirrored module entry; open when discovering which Domain Skill owns a cross-cutting architecture concern.

More from thedivergentai/GD-Agentic-Skills

SkillDescription
godot-2d-animationExpert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs. Use when implementing sprite frame animations, procedural animation (squash/stretch), cutout bone hierarchies, or frame-perfect timing systems. Trigger keywords: AnimatedSprite2D, SpriteFrames, animation_finished, animation_looped, frame_changed, frame_progress, set_frame_and_progress, cutout animation, skeletal 2D, Bone2D, procedural animation, animation state machine, advance(0).
godot-2d-physicsExpert patterns for Godot 2D physics including collision layers/masks, Area2D triggers, raycasting, and PhysicsDirectSpaceState2D queries. Use when implementing collision detection, trigger zones, line-of-sight systems, or manual physics queries. Trigger keywords: CollisionShape2D, CollisionPolygon2D, collision_layer, collision_mask, set_collision_layer_value, set_collision_mask_value, Area2D, body_entered, body_exited, RayCast2D, force_raycast_update, PhysicsPointQueryParameters2D, PhysicsShapeQueryParameters2D, direct_space_state, move_and_collide, move_and_slide.
godot-3d-lightingExpert patterns for Godot 3D lighting including DirectionalLight3D shadow cascades, OmniLight3D attenuation, SpotLight3D projectors, VoxelGI vs SDFGI, and LightmapGI baking. Use when implementing realistic 3D lighting, shadow optimization, global illumination, or light probes. Trigger keywords: DirectionalLight3D, OmniLight3D, SpotLight3D, shadow_enabled, directional_shadow_mode, directional_shadow_split, omni_range, omni_attenuation, spot_range, spot_angle, VoxelGI, SDFGI, LightmapGI, ReflectionProbe, Environment, WorldEnvironment.
godot-3d-materialsExpert patterns for Godot 3D PBR materials using StandardMaterial3D including albedo, metallic/roughness workflows, normal maps, ORM texture packing, transparency modes, and shader conversion. Use when creating realistic 3D surfaces, PBR workflows, or material optimization. Trigger keywords: StandardMaterial3D, BaseMaterial3D, albedo_texture, metallic, metallic_texture, roughness, roughness_texture, normal_texture, normal_enabled, orm_texture, transparency, alpha_scissor, alpha_hash, cull_mode, ShaderMaterial, shader parameters.
godot-3d-world-buildingExpert patterns for 3D level design using GridMap with MeshLibrary, CSG constructive solid geometry, occlusion, and runtime GridMap builders. Use when building 3D levels, modular tilesets, or BSP-style geometry. For sky/fog/Environment recipes, route to godot-3d-lighting. Trigger keywords: GridMap, MeshLibrary, set_cell_item, get_cell_item, map_to_local, local_to_map, CSGCombiner3D, CSGBox3D, CSGSphere3D, CSGPolygon3D, OccluderInstance3D, bake CSG.
godot-ability-systemExpert patterns for RPG/action ability systems including cooldown strategies, combo systems, ability chaining, skill trees with prerequisites, upgrade paths, and resource management. Use when implementing unlockable abilities, character progression, or complex skill systems. Trigger keywords: PlayerAbility, AbilityManager, cooldown, SkillTree, SkillNode, prerequisites, can_use, execute, ComboSystem, ability_chain, global_cooldown, charge_system, upgrade_path.
godot-adapt-2d-to-3dExpert patterns for migrating 2D games to 3D including node type conversions, camera systems (third-person, first-person, orbit), physics layer migration, sprite-to-model art pipeline, and control scheme adaptations. Use when porting 2D projects to 3D or adding 3D elements. Trigger keywords: CharacterBody2D to CharacterBody3D, Area2D to Area3D, Camera2D to Camera3D, Vector2 to Vector3, collision_layer migration, sprite to MeshInstance3D, 2D to 3D conversion.
godot-adapt-3d-to-2dExpert patterns for simplifying 3D games to 2D including dimension reduction strategies, 2.5D fake-depth, isometric ports, camera flattening, physics conversion, 3D-to-sprite art pipeline, and control simplification. Use when porting 3D to 2D, building 2.5D / isometric / fake-depth gameplay, creating 2D versions for mobile, or prototyping. Trigger keywords: CharacterBody3D to CharacterBody2D, Camera3D to Camera2D, Vector3 to Vector2, flatten Z-axis, 2.5D, isometric, fake depth, Y-sort, simulated Z, orthogonal projection, 3D to sprite conversion, performance optimization.
godot-adapt-desktop-to-mobileExpert patterns for porting desktop games to mobile including touch control schemes (virtual joystick, gesture detection), UI scaling for small screens, performance optimization for mobile GPUs, battery life management, and platform-specific features. Use when creating mobile ports or cross-platform mobile builds. Trigger keywords: TouchScreenButton, virtual_joystick, gesture_detector, InputEventScreenTouch, InputEventScreenDrag, mobile_optimization, battery_saving, adaptive_performance, MOBILE_ENABLED.
godot-adapt-mobile-to-desktopExpert patterns for scaling mobile games to desktop including mouse/keyboard controls, increased resolution and graphical fidelity, expanded UI layouts, settings menus, window management, and platform-specific features. Use when creating desktop ports or cross-platform releases. Trigger keywords: mouse_controls, keyboard_shortcuts, resolution_scaling, graphics_settings, fullscreen_toggle, window_modes, Steam_integration, desktop_optimization.