$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-compositionExpert architectural standards for building scalable Godot GAMES (RPGs, Platformers, Shooters) using the Composition pattern (Entity-Component). Use when designing player controllers, NPCs, enemies, weapons, or complex gameplay systems. Enforces \"Has-A\" relationships for game e
| 1 | ## Godot 4.7 Baseline |
| 2 | |
| 3 | - Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18). |
| 4 | - 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. |
| 5 | - **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes. |
| 6 | |
| 7 | # Godot Composition Architecture |
| 8 | |
| 9 | ## Core Philosophy |
| 10 | This skill enforces **Composition over Inheritance** ("Has-a" vs "Is-a"). |
| 11 | In Godot, Nodes **are** components. A complex entity (Player) is simply an Orchestrator managing specialized Worker Nodes (Components). |
| 12 | |
| 13 | ### The Golden Rules |
| 14 | 1. **Single Responsibility**: One script = One job. |
| 15 | 2. **Encapsulation**: Components are "selfish." They handle their internal logic but don't know *who* owns them. |
| 16 | 3. **The Orchestrator**: The root script (e.g., `player.gd`) does **no logic**. It only manages state and passes data between components. |
| 17 | 4. **Decoupling**: Components communicate via **Signals** (up) and **Methods** (down). |
| 18 | |
| 19 | --- |
| 20 | |
| 21 | ## Available Scripts |
| 22 | |
| 23 | ### [health_component.gd](scripts/health_component.gd) |
| 24 | Specialized Node for managing lifespan, damage logic, and death signals across any entity. |
| 25 | |
| 26 | ### [hit_box_component.gd](scripts/hit_box_component.gd) |
| 27 | Area-based component for intercepting damage and delegating it to a HealthComponent. |
| 28 | |
| 29 | ### [hurt_box_component.gd](scripts/hurt_box_component.gd) |
| 30 | Area-based component for dealing damage specifically to HitBoxComponents. |
| 31 | |
| 32 | ### [velocity_component.gd](scripts/velocity_component.gd) |
| 33 | Encapsulated movement and acceleration logic for reuse across Players and Enemies. |
| 34 | |
| 35 | ### [interaction_component.gd](scripts/interaction_component.gd) |
| 36 | Decoupled interaction handler using injecting `Callable` logic for context-aware actions. |
| 37 | |
| 38 | ### [follower_component.gd](scripts/follower_component.gd) |
| 39 | Decoupled tracking logic using `NodePath` injection for smooth entity following. |
| 40 | |
| 41 | ### [state_component_vsm.gd](scripts/state_component_vsm.gd) |
| 42 | Component-based state machine pattern using child nodes as individual states. |
| 43 | |
| 44 | ### [status_effect_component.gd](scripts/status_effect_component.gd) |
| 45 | Managing temporary modifiers (buffs/debuffs) by stacking effect scenes as children. |
| 46 | |
| 47 | ### [visual_sync_component.gd](scripts/visual_sync_component.gd) |
| 48 | Separating logical state (velocity/direction) from visual representation (sprite flipping). |
| 49 | |
| 50 | ### [composition_root_init.gd](scripts/composition_root_init.gd) |
| 51 | The "Orchestrator" pattern for wiring and connecting components in a parent node. |
| 52 | |
| 53 | ## NEVER Do in Composition |
| 54 | |
| 55 | - **NEVER use deep inheritance chains** (e.g., `Player > Entity > LivingThing > Node`) — Creates brittle "God Classes" that are hard to refactor [21]. |
| 56 | - **NEVER use `get_node()` or `$` for components** — This breaks if the scene tree is rearranged. Always use `@export` or `%UniqueNames` [22]. |
| 57 | - **NEVER let a component reference its parent script directly** — This makes the component impossible to reuse. Use signals or dependency injection [23]. |
| 58 | - **NEVER mix Input, Physics, and Game Logic in one script** — This violates Single Responsibility. Split them into specialized components [24, 13]. |
| 59 | - **NEVER create components that require a specific SceneTree structure** — A component should be "selfish" and only care about its own properties and direct children. |
| 60 | - **NEVER use inheritance to "add a feature"** — If you want an enemy to shoot, add a `ShootingComponent`, don't make it inherit from `ShooterEnemy`. |
| 61 | - **NEVER hardcode component dependencies** — If `CombatComponent` needs `HealthComponent`, look it up in `_ready()` or inject it via the parent [11]. |
| 62 | - **NEVER treat Godot nodes as pure data** — Nodes provide lifecycle (`_process`) and signals. If you only need data, use a `Resource`. |
| 63 | - **NEVER ignore the Node lifecycle in components** — Use `_enter_tree()` and `_exit_tree()` for setup/cleanup that must happen regardless of the parent's state. |
| 64 | - **NEVER hide component points of access** — Expose `NodePath` or `Callable` properties so the parent can wire the component in the Inspector [13]. |
| 65 | |
| 66 | --- |
| 67 | |
| 68 | ## Implementation Standards |
| 69 | |
| 70 | ### 1. Connection Strategy: Typed Exports |
| 71 | Do not rely on tree order. Use explicit dependency injection via `@export` with static typing. |
| 72 | |
| 73 | **The "Godot Way" for strict godot-composition:** |
| 74 | ```gdscript |
| 75 | # The Orchestrator (e.g., player.gd) |
| 76 | class_name Player extends CharacterBody3D |
| 77 | |
| 78 | # Dependency Injection: Define the "slots" in the backpack |
| 79 | @export var health_component: HealthComponent |
| 80 | @export var movement |