[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KR7KVZF4GB8XJZXCD62G91":3,"skill-same:01M6KR7KVZF4GB8XJZXCD62G91":62},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":34,"linkOnly":35,"markdownContent":36,"markdownBody":37,"frontMatter":38,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":42,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":45,"ownerDescription":46,"updatedAt":47,"install":48,"resources":61},"01M6KR7KVZF4GB8XJZXCD62G91","component-system",null,"Use when building reusable node components — composition patterns, component communication, and interface design","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fcomponent-system\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],"component","system","component system","design","components","communication","Composition","node","use","reusable","patterns","interface design","interface","composition patterns","when","2026-11-10 10:12:30",false,"---\nname: component-system\ndescription: Use when building reusable node components — composition patterns, component communication, and interface design\n---\n\n# Component System in Godot 4.3+\n\nBuild behavior through composition. Attach small, focused components to any entity rather than climbing an inheritance chain. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **scene-organization** for scene tree composition, **event-bus** for decoupled component communication, **resource-pattern** for data-driven component configuration, **physics-system** for Area2D\u002F3D overlap detection and collision shapes, **ability-system** for an AbilityComponent example built on this pattern.\n\n---\n\n## 1. Why Components\n\n| Problem with inheritance | How components solve it |\n|--------------------------|-------------------------|\n| Deep chains are brittle — change one class, break many | Each component is an isolated scene with a single job |\n| Sharing behavior across unrelated entities requires awkward base classes | Drop a component onto any entity that needs that behavior |\n| Adding a new combination means a new subclass | Mix and match components freely at the scene level |\n\nKey benefits:\n\n- **Reuse across entities** — a `HealthComponent` works on a player, an enemy, a destructible crate, or a boss with no code changes.\n- **Separation of concerns** — damage detection, health tracking, and state animation are each their own file. Debugging is local.\n- **Mix-and-match behaviors** — give an enemy a `HitboxComponent` and a `PatrolComponent` independently. Removing one does not affect the other.\n\n---\n\n## 2. Component Design Rules\n\n1. **One responsibility per component.** If you find yourself naming it `HealthAndShieldAndRegenComponent`, split it.\n2. **Communicate via signals, not direct sibling access.** A component must not call `get_parent().get_node(\"SiblingComponent\")`. Emit a signal instead.\n3. **Stateless where possible.** Prefer deriving state from inputs and `@export` configuration over storing mutable state. When state is necessary, keep it private.\n4. **Use `@export` for all configuration.** Damage amount, cooldown duration, and layer masks belong in the Inspector, not hardcoded constants.\n\n---\n\n## 3. Common Components\n\n| Component | Purpose | Key Signals |\n|---|---|---|\n| `HealthComponent` | Tracks current and max HP, applies damage and healing | `health_changed(current, maximum)`, `died` |\n| `HitboxComponent` | Detects overlapping hurtboxes and triggers damage | `hit(target_hurtbox)` |\n| `HurtboxComponent` | Receives hits, routes damage to `HealthComponent` | `hurt(damage_amount)` |\n| `InteractableComponent` | Marks an entity as interactable and fires on player overlap | `interacted(interactor)` |\n| `StateMachineComponent` | Delegates `_process` and `_physics_process` to child state nodes | `state_changed(from, to)` |\n\n---\n\n## 4. HitboxComponent\n\nAttach to any entity that deals damage. Configure `damage` in the Inspector.\n\n### GDScript (`hitbox_component.gd`)\n\n```gdscript\nclass_name HitboxComponent\nextends Area2D\n\n## Damage dealt to the target hurtbox on contact.\n@export var damage: int = 10\n\n## Minimum seconds between successive hits (0 = no cooldown).\n@export var cooldown_duration: float = 0.5\n\nsignal hit(target_hurtbox: HurtboxComponent)\n\nvar _on_cooldown: bool = false\n\n@onready var _cooldown_timer: Timer = _build_timer()\n\n\nfunc _ready() -> void:\n\tarea_entered.connect(_on_area_entered)\n\n\nfunc _on_area_entered(area: Area2D) -> void:\n\tif _on_cooldown:\n\t\treturn\n\tif area is not HurtboxComponent:\n\t\treturn\n\thit.emit(area)\n\tarea.receive_hit(damage)\n\tif cooldown_duration > 0.0:\n\t\t_on_cooldown = true\n\t\t_cooldown_timer.start(cooldown_duration)\n\n\nfunc _on_cooldown_timeout() -> void:\n\t_on_cooldown = false\n\n\nfunc _build_timer() -> Timer:\n\tvar t := Timer.new()\n\tt.one_shot = true\n\tt.timeout.connect(_on_cooldown_timeout)\n\tadd_child(t)\n\treturn t\n```\n\n### C# (`HitboxComponent.cs`)\n\n```csharp\nusing Godot;\n\npublic partial class HitboxComponent : Area2D\n{\n    \u002F\u002F\u002F \u003Csummary>Damage dealt to the target hurtbox on contact.\u003C\u002Fsummary>\n    [Export] public int Damage { get; set; } = 10;\n\n    \u002F\u002F\u002F \u003Csummary>Minimum seconds between successive hits (0 = no cooldown).\u003C\u002Fsummary>\n    [Export] public float CooldownDuration { get; set; } = 0.5f;\n\n    [Signal] public delegate void HitEventHandler(HurtboxComponent targetHurtbox);\n\n    private bool _onCooldown;\n    private Timer _cooldownTimer;\n\n    public override void _Ready()\n    {\n        _cooldownTimer = new Timer { OneShot = true };\n        _cooldownTimer.Timeout += OnCooldownTimeout;\n        AddChild(_cooldownTimer);\n\n        AreaEntered += OnAreaEntered;\n    }\n\n    private void OnAreaEntered(Area2D area)\n    {\n        if (_onCooldown) return;\n        if (area is not HurtboxComponent hurtbox) return;\n\n        EmitSignal(SignalName.Hit, hurtbox);\n        hurtbox.ReceiveHit(Damage);\n\n        if (CooldownDuration > 0f)\n        {\n            _onCooldown = true;\n            _cooldownTimer.Start(CooldownDuration);\n        }\n    }\n\n    private void OnCooldownTimeout() => _onCooldown = false;\n}\n```\n\n---\n\n## 5. HurtboxComponent\n\nAttach to any entity that can take damage. Wire it to a sibling `HealthComponent` via `@export`.\n\n### GDScript (`hurtbox_component.gd`)\n\n```gdscript\nclass_name HurtboxComponent\nextends Area2D\n\n## Reference to the HealthComponent on the same entity.\n@export var health_component: HealthComponent\n\n## Invincibility frame duration in seconds (0 = none).\n@export var invincibility_duration: float = 0.0\n\nsignal hurt(damage_amount: int)\n\nvar _invincible: bool = false\n\n@onready var _iframes_timer: Timer = _build_timer()\n\n\nfunc receive_hit(damage: int) -> void:\n\tif _invincible:\n\t\treturn\n\thurt.emit(damage)\n\tif health_component:\n\t\thealth_component.take_damage(damage)\n\tif invincibility_duration > 0.0:\n\t\t_invincible = true\n\t\t_iframes_timer.start(invincibility_duration)\n\n\nfunc _on_iframes_timeout() -> void:\n\t_invincible = false\n\n\nfunc _build_timer() -> Timer:\n\tvar t := Timer.new()\n\tt.one_shot = true\n\tt.timeout.connect(_on_iframes_timeout)\n\tadd_child(t)\n\treturn t\n```\n\n### C# (`HurtboxComponent.cs`)\n\n```csharp\nusing Godot;\n\npublic partial class HurtboxComponent : Area2D\n{\n    \u002F\u002F\u002F \u003Csummary>Reference to the HealthComponent on the same entity.\u003C\u002Fsummary>\n    [Export] public HealthComponent HealthComponent { get; set; }\n\n    \u002F\u002F\u002F \u003Csummary>Invincibility frame duration in seconds (0 = none).\u003C\u002Fsummary>\n    [Export] public float InvincibilityDuration { get; set; } = 0f;\n\n    [Signal] public delegate void HurtEventHandler(int damageAmount);\n\n    private bool _invincible;\n    private Timer _iframesTimer;\n\n    public override void _Ready()\n    {\n        _iframesTimer = new Timer { OneShot = true };\n        _iframesTimer.Timeout += OnIframesTimeout;\n        AddChild(_iframesTimer);\n    }\n\n    public void ReceiveHit(int damage)\n    {\n        if (_invincible) return;\n\n        EmitSignal(SignalName.Hurt, damage);\n        HealthComponent?.TakeDamage(damage);\n\n        if (InvincibilityDuration > 0f)\n        {\n            _invincible = true;\n            _iframesTimer.Start(InvincibilityDuration);\n        }\n    }\n\n    private void OnIframesTimeout() => _invincible = false;\n}\n```\n\n---\n\n## 6. Component Communication\n\nComponents must not call methods on siblings directly. Use signals to keep them decoupled.\n\n```\n┌─────────────────────────────────────────────────────┐\n│  Entity (CharacterBody2D)                            │\n│                                                      │\n│  ┌──────────────┐    hit(hurtbox)                    │\n│  │ HitboxComponent ──────────────────────────────┐  │\n│  └──────────────┘                                 │  │\n│                                                   ▼  │\n│                              ┌─────────────────────┐ │\n│                              │  HurtboxComponent   │ │\n│                              │  receive_hit(dmg)   │ │\n│                              │  ──── calls ──────► │ │\n│                              │  HealthComponent    │ │\n│                              │  .take_damage(dmg) │ │\n│                              └────────┬────────────┘ │\n│                                       │              │\n│                              health_changed \u002F died   │\n│                                       │              │\n│                              ┌────────▼────────────┐ │\n│                              │  HealthComponent    │ │\n│                              │  emits: died        │ │\n│                              └─────────────────────┘ │\n└─────────────────────────────────────────────────────┘\n```\n\n**Flow explained:**\n\n1. `HitboxComponent` detects an overlapping `HurtboxComponent` via `area_entered`.\n2. It emits `hit(target_hurtbox)` (for the entity's own logic, e.g. playing a sound) and calls `target_hurtbox.receive_hit(damage)` — the only cross-component call, and it targets the direct interface of the hurtbox, not a sibling.\n3. `HurtboxComponent.receive_hit()` emits `hurt(damage_amount)` for animation\u002FVFX, then calls `health_component.take_damage(damage)` on its explicitly wired reference.\n4. `HealthComponent.take_damage()` updates HP and emits `health_changed` or `died`. Listeners (UI, GameManager, etc.) connect to those signals without touching the combat components.\n\n---\n\n## 7. Wiring Components\n\nThree patterns in order of preference:\n\n### @export node reference — most flexible, works across the scene tree\n\n```gdscript\n# hurtbox_component.gd\n@export var health_component: HealthComponent\n\n# Inspector: drag the HealthComponent node into the slot.\n```\n\n> **Gotcha:** `@export` node references are wired via the editor inspector. If you build scenes programmatically, nothing assigns the reference and it is null at runtime. In that case, wire it explicitly in the parent's `_ready()`:\n> ```gdscript\n> hurtbox.health_component = health_component\n> ```\n\n### @onready direct child — simple when the component is a known child\n\n```gdscript\n# enemy.gd\n@onready var health: HealthComponent = $HealthComponent\n@onready var hurtbox: HurtboxComponent = $HurtboxComponent\n```\n\n### get_node pattern — when the path is dynamic or optional\n\n```gdscript\nfunc _ready() -> void:\n\tvar health := get_node_or_null(\"HealthComponent\") as HealthComponent\n\tif health:\n\t\thealth.died.connect(_on_died)\n```\n\n> Prefer `@export` when the wired node lives elsewhere in the tree. Prefer `@onready` for direct children that are always present. Use `get_node_or_null` when the component is optional.\n\n### C# parity\n\n```csharp\n\u002F\u002F Pattern 1: [Export] property — drag-and-drop in the Inspector.\npublic partial class HurtboxComponent : Area3D\n{\n    [Export] public HealthComponent Health { get; set; }\n}\n\n\u002F\u002F Pattern 2: GetNode\u003CT> for a known child path (equivalent to @onready var x := $Path).\npublic partial class Enemy : CharacterBody3D\n{\n    private HealthComponent _health;\n    private HurtboxComponent _hurtbox;\n\n    public override void _Ready()\n    {\n        _health = GetNode\u003CHealthComponent>(\"HealthComponent\");\n        _hurtbox = GetNode\u003CHurtboxComponent>(\"HurtboxComponent\");\n        _health.Died += QueueFree;\n    }\n}\n\n\u002F\u002F Pattern 3: GetNodeOrNull\u003CT> when the component is optional (equivalent to get_node_or_null).\npublic partial class Pickup : Node3D\n{\n    public override void _Ready()\n    {\n        var health = GetNodeOrNull\u003CHealthComponent>(\"HealthComponent\");\n        if (health != null)\n            health.Died += OnDied;\n    }\n\n    private void OnDied() { \u002F* ... *\u002F }\n}\n```\n\n---\n\n## 8. Finding Components at Runtime\n\nUse a static utility to locate the first component of a given type on any entity. This avoids hardcoding node names across different entity scenes.\n\n### GDScript (`component_utils.gd`)\n\n```gdscript\nclass_name ComponentUtils\n\n\n## Returns the first child of [param entity] that is an instance of [param component_type],\n## or null if none is found.\nstatic func get_component(entity: Node, component_type: GDScript) -> Node:\n\tfor child in entity.get_children():\n\t\tif is_instance_of(child, component_type):\n\t\t\treturn child\n\treturn null\n\n\n## Example usage:\n##   var health := ComponentUtils.get_component(enemy, HealthComponent) as HealthComponent\n##   if health:\n##       health.take_damage(5)\n```\n\n### C# (`ComponentUtils.cs`)\n\n```csharp\nusing Godot;\n\npublic static class ComponentUtils\n{\n    \u002F\u002F\u002F \u003Csummary>\n    \u002F\u002F\u002F Returns the first child of \u003Cparamref name=\"entity\"\u002F> that is of type\n    \u002F\u002F\u002F \u003Ctypeparamref name=\"T\"\u002F>, or null if none is found.\n    \u002F\u002F\u002F \u003C\u002Fsummary>\n    public static T GetComponent\u003CT>(Node entity) where T : Node\n    {\n        foreach (var child in entity.GetChildren())\n        {\n            if (child is T component)\n                return component;\n        }\n        return null;\n    }\n}\n\n\u002F\u002F Example usage:\n\u002F\u002F   var health = ComponentUtils.GetComponent\u003CHealthComponent>(enemy);\n\u002F\u002F   health?.TakeDamage(5);\n```\n\n---\n\n## 9. Implementation Checklist\n\n- [ ] Each component is saved as its own `.tscn` scene and reused by instancing\n- [ ] Components communicate through signals — no `get_parent().get_node(\"Sibling\")` calls\n- [ ] No direct sibling access anywhere inside a component script\n- [ ] All tuneable values (`damage`, `max_health`, `cooldown_duration`) are `@export`\n- [ ] Each component can be tested by attaching it to a minimal test scene in isolation\n","# Component System in Godot 4.3+\n\nBuild behavior through composition. Attach small, focused components to any entity rather than climbing an inheritance chain. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **scene-organization** for scene tree composition, **event-bus** for decoupled component communication, **resource-pattern** for data-driven component configuration, **physics-system** for Area2D\u002F3D overlap detection and collision shapes, **ability-system** for an AbilityComponent example built on this pattern.\n\n---\n\n## 1. Why Components\n\n| Problem with inheritance | How components solve it |\n|--------------------------|-------------------------|\n| Deep chains are brittle — change one class, break many | Each component is an isolated scene with a single job |\n| Sharing behavior across unrelated entities requires awkward base classes | Drop a component onto any entity that needs that behavior |\n| Adding a new combination means a new subclass | Mix and match components freely at the scene level |\n\nKey benefits:\n\n- **Reuse across entities** — a `HealthComponent` works on a player, an enemy, a destructible crate, or a boss with no code changes.\n- **Separation of concerns** — damage detection, health tracking, and state animation are each their own file. Debugging is local.\n- **Mix-and-match behaviors** — give an enemy a `HitboxComponent` and a `PatrolComponent` independently. Removing one does not affect the other.\n\n---\n\n## 2. Component Design Rules\n\n1. **One responsibility per component.** If you find yourself naming it `HealthAndShieldAndRegenComponent`, split it.\n2. **Communicate via signals, not direct sibling access.** A component must not call `get_parent().get_node(\"SiblingComponent\")`. Emit a signal instead.\n3. **Stateless where possible.** Prefer deriving state from inputs and `@export` configuration over storing mutable state. When state is necessary, keep it private.\n4. **Use `@export` for all configuration.** Damage amount, cooldown duration, and layer masks belong in the Inspector, not hardcoded constants.\n\n---\n\n## 3. Common Components\n\n| Component | Purpose | Key Signals |\n|---|---|---|\n| `HealthComponent` | Tracks current and max HP, applies damage and healing | `health_changed(current, maximum)`, `died` |\n| `HitboxComponent` | Detects overlapping hurtboxes and triggers damage | `hit(target_hurtbox)` |\n| `HurtboxComponent` | Receives hits, routes damage to `HealthComponent` | `hurt(damage_amount)` |\n| `InteractableComponent` | Marks an entity as interactable and fires on player overlap | `interacted(interactor)` |\n| `StateMachineComponent` | Delegates `_process` and `_physics_process` to child state nodes | `state_changed(from, to)` |\n\n---\n\n## 4. HitboxComponent\n\nAttach to any entity that deals damage. Configure `damage` in the Inspector.\n\n### GDScript (`hitbox_component.gd`)\n\n```gdscript\nclass_name HitboxComponent\nextends Area2D\n\n## Damage dealt to the target hurtbox on contact.\n@export var damage: int = 10\n\n## Minimum seconds between successive hits (0 = no cooldown).\n@export var cooldown_duration: float = 0.5\n\nsignal hit(target_hurtbox: HurtboxComponent)\n\nvar _on_cooldown: bool = false\n\n@onready var _cooldown_timer: Timer = _build_timer()\n\n\nfunc _ready() -> void:\n\tarea_entered.connect(_on_area_entered)\n\n\nfunc _on_area_entered(area: Area2D) -> void:\n\tif _on_cooldown:\n\t\treturn\n\tif area is not HurtboxComponent:\n\t\treturn\n\thit.emit(area)\n\tarea.receive_hit(damage)\n\tif cooldown_duration > 0.0:\n\t\t_on_cooldown = true\n\t\t_cooldown_timer.start(cooldown_duration)\n\n\nfunc _on_cooldown_timeout() -> void:\n\t_on_cooldown = false\n\n\nfunc _build_timer() -> Timer:\n\tvar t := Timer.new()\n\tt.one_shot = true\n\tt.timeout.connect(_on_cooldown_timeout)\n\tadd_child(t)\n\treturn t\n```\n\n### C# (`HitboxComponent.cs`)\n\n```csharp\nusing Godot;\n\npublic partial class HitboxComponent : Area2D\n{\n    \u002F\u002F\u002F \u003Csummary>Damage dealt to the target hurtbox on contact.\u003C\u002Fsummary>\n    [Export] public int Damage { get; set; } = 10;\n\n    \u002F\u002F\u002F \u003Csummary>Minimum seconds between successive hits (0 = no cooldown).\u003C\u002Fsummary>\n    [Export] public float CooldownDuration { get; set; } = 0.5f;\n\n    [Signal] public delegate void HitEventHandler(HurtboxComponent targetHurtbox);\n\n    private bool _onCooldown;\n    private Timer _cooldownTimer;\n\n    public override void _Ready()\n    {\n        _cooldownTimer = new Timer { OneShot = true };\n        _cooldownTimer.Timeout += OnCooldownTimeout;\n        AddChild(_cooldownTimer);\n\n        AreaEntered += OnAreaEntered;\n    }\n\n    private void OnAreaEntered(Area2D area)\n    {\n        if (_onCooldown) return;\n        if (area is not HurtboxComponent hurtbox) return;\n\n        EmitSignal(SignalName.Hit, hurtbox);\n        hurtbox.ReceiveHit(Damage);\n\n        if (CooldownDuration > 0f)\n        {\n            _onCooldown = true;\n            _cooldownTimer.Start(CooldownDuration);\n        }\n    }\n\n    private void OnCooldownTimeout() => _onCooldown = false;\n}\n```\n\n---\n\n## 5. HurtboxComponent\n\nAttach to any entity that can take damage. Wire it to a sibling `HealthComponent` via `@export`.\n\n### GDScript (`hurtbox_component.gd`)\n\n```gdscript\nclass_name HurtboxComponent\nextends Area2D\n\n## Reference to the HealthComponent on the same entity.\n@export var health_component: HealthComponent\n\n## Invincibility frame duration in seconds (0 = none).\n@export var invincibility_duration: float = 0.0\n\nsignal hurt(damage_amount: int)\n\nvar _invincible: bool = false\n\n@onready var _iframes_timer: Timer = _build_timer()\n\n\nfunc receive_hit(damage: int) -> void:\n\tif _invincible:\n\t\treturn\n\thurt.emit(damage)\n\tif health_component:\n\t\thealth_component.take_damage(damage)\n\tif invincibility_duration > 0.0:\n\t\t_invincible = true\n\t\t_iframes_timer.start(invincibility_duration)\n\n\nfunc _on_iframes_timeout() -> void:\n\t_invincible = false\n\n\nfunc _build_timer() -> Timer:\n\tvar t := Timer.new()\n\tt.one_shot = true\n\tt.timeout.connect(_on_iframes_timeout)\n\tadd_child(t)\n\treturn t\n```\n\n### C# (`HurtboxComponent.cs`)\n\n```csharp\nusing Godot;\n\npublic partial class HurtboxComponent : Area2D\n{\n    \u002F\u002F\u002F \u003Csummary>Reference to the HealthComponent on the same entity.\u003C\u002Fsummary>\n    [Export] public HealthComponent HealthComponent { get; set; }\n\n    \u002F\u002F\u002F \u003Csummary>Invincibility frame duration in seconds (0 = none).\u003C\u002Fsummary>\n    [Export] public float InvincibilityDuration { get; set; } = 0f;\n\n    [Signal] public delegate void HurtEventHandler(int damageAmount);\n\n    private bool _invincible;\n    private Timer _iframesTimer;\n\n    public override void _Ready()\n    {\n        _iframesTimer = new Timer { OneShot = true };\n        _iframesTimer.Timeout += OnIframesTimeout;\n        AddChild(_iframesTimer);\n    }\n\n    public void ReceiveHit(int damage)\n    {\n        if (_invincible) return;\n\n        EmitSignal(SignalName.Hurt, damage);\n        HealthComponent?.TakeDamage(damage);\n\n        if (InvincibilityDuration > 0f)\n        {\n            _invincible = true;\n            _iframesTimer.Start(InvincibilityDuration);\n        }\n    }\n\n    private void OnIframesTimeout() => _invincible = false;\n}\n```\n\n---\n\n## 6. Component Communication\n\nComponents must not call methods on siblings directly. Use signals to keep them decoupled.\n\n```\n┌─────────────────────────────────────────────────────┐\n│  Entity (CharacterBody2D)                            │\n│                                                      │\n│  ┌──────────────┐    hit(hurtbox)                    │\n│  │ HitboxComponent ──────────────────────────────┐  │\n│  └──────────────┘                                 │  │\n│                                                   ▼  │\n│                              ┌─────────────────────┐ │\n│                              │  HurtboxComponent   │ │\n│                              │  receive_hit(dmg)   │ │\n│                              │  ──── calls ──────► │ │\n│                              │  HealthComponent    │ │\n│                              │  .take_damage(dmg) │ │\n│                              └────────┬────────────┘ │\n│                                       │              │\n│                              health_changed \u002F died   │\n│                                       │              │\n│                              ┌────────▼────────────┐ │\n│                              │  HealthComponent    │ │\n│                              │  emits: died        │ │\n│                              └─────────────────────┘ │\n└─────────────────────────────────────────────────────┘\n```\n\n**Flow explained:**\n\n1. `HitboxComponent` detects an overlapping `HurtboxComponent` via `area_entered`.\n2. It emits `hit(target_hurtbox)` (for the entity's own logic, e.g. playing a sound) and calls `target_hurtbox.receive_hit(damage)` — the only cross-component call, and it targets the direct interface of the hurtbox, not a sibling.\n3. `HurtboxComponent.receive_hit()` emits `hurt(damage_amount)` for animation\u002FVFX, then calls `health_component.take_damage(damage)` on its explicitly wired reference.\n4. `HealthComponent.take_damage()` updates HP and emits `health_changed` or `died`. Listeners (UI, GameManager, etc.) connect to those signals without touching the combat components.\n\n---\n\n## 7. Wiring Components\n\nThree patterns in order of preference:\n\n### @export node reference — most flexible, works across the scene tree\n\n```gdscript\n# hurtbox_component.gd\n@export var health_component: HealthComponent\n\n# Inspector: drag the HealthComponent node into the slot.\n```\n\n> **Gotcha:** `@export` node references are wired via the editor inspector. If you build scenes programmatically, nothing assigns the reference and it is null at runtime. In that case, wire it explicitly in the parent's `_ready()`:\n> ```gdscript\n> hurtbox.health_component = health_component\n> ```\n\n### @onready direct child — simple when the component is a known child\n\n```gdscript\n# enemy.gd\n@onready var health: HealthComponent = $HealthComponent\n@onready var hurtbox: HurtboxComponent = $HurtboxComponent\n```\n\n### get_node pattern — when the path is dynamic or optional\n\n```gdscript\nfunc _ready() -> void:\n\tvar health := get_node_or_null(\"HealthComponent\") as HealthComponent\n\tif health:\n\t\thealth.died.connect(_on_died)\n```\n\n> Prefer `@export` when the wired node lives elsewhere in the tree. Prefer `@onready` for direct children that are always present. Use `get_node_or_null` when the component is optional.\n\n### C# parity\n\n```csharp\n\u002F\u002F Pattern 1: [Export] property — drag-and-drop in the Inspector.\npublic partial class HurtboxComponent : Area3D\n{\n    [Export] public HealthComponent Health { get; set; }\n}\n\n\u002F\u002F Pattern 2: GetNode\u003CT> for a known child path (equivalent to @onready var x := $Path).\npublic partial class Enemy : CharacterBody3D\n{\n    private HealthComponent _health;\n    private HurtboxComponent _hurtbox;\n\n    public override void _Ready()\n    {\n        _health = GetNode\u003CHealthComponent>(\"HealthComponent\");\n        _hurtbox = GetNode\u003CHurtboxComponent>(\"HurtboxComponent\");\n        _health.Died += QueueFree;\n    }\n}\n\n\u002F\u002F Pattern 3: GetNodeOrNull\u003CT> when the component is optional (equivalent to get_node_or_null).\npublic partial class Pickup : Node3D\n{\n    public override void _Ready()\n    {\n        var health = GetNodeOrNull\u003CHealthComponent>(\"HealthComponent\");\n        if (health != null)\n            health.Died += OnDied;\n    }\n\n    private void OnDied() { \u002F* ... *\u002F }\n}\n```\n\n---\n\n## 8. Finding Components at Runtime\n\nUse a static utility to locate the first component of a given type on any entity. This avoids hardcoding node names across different entity scenes.\n\n### GDScript (`component_utils.gd`)\n\n```gdscript\nclass_name ComponentUtils\n\n\n## Returns the first child of [param entity] that is an instance of [param component_type],\n## or null if none is found.\nstatic func get_component(entity: Node, component_type: GDScript) -> Node:\n\tfor child in entity.get_children():\n\t\tif is_instance_of(child, component_type):\n\t\t\treturn child\n\treturn null\n\n\n## Example usage:\n##   var health := ComponentUtils.get_component(enemy, HealthComponent) as HealthComponent\n##   if health:\n##       health.take_damage(5)\n```\n\n### C# (`ComponentUtils.cs`)\n\n```csharp\nusing Godot;\n\npublic static class ComponentUtils\n{\n    \u002F\u002F\u002F \u003Csummary>\n    \u002F\u002F\u002F Returns the first child of \u003Cparamref name=\"entity\"\u002F> that is of type\n    \u002F\u002F\u002F \u003Ctypeparamref name=\"T\"\u002F>, or null if none is found.\n    \u002F\u002F\u002F \u003C\u002Fsummary>\n    public static T GetComponent\u003CT>(Node entity) where T : Node\n    {\n        foreach (var child in entity.GetChildren())\n        {\n            if (child is T component)\n                return component;\n        }\n        return null;\n    }\n}\n\n\u002F\u002F Example usage:\n\u002F\u002F   var health = ComponentUtils.GetComponent\u003CHealthComponent>(enemy);\n\u002F\u002F   health?.TakeDamage(5);\n```\n\n---\n\n## 9. Implementation Checklist\n\n- [ ] Each component is saved as its own `.tscn` scene and reused by instancing\n- [ ] Components communicate through signals — no `get_parent().get_node(\"Sibling\")` calls\n- [ ] No direct sibling access anywhere inside a component script\n- [ ] All tuneable values (`damage`, `max_health`, `cooldown_duration`) are `@export`\n- [ ] Each component can be tested by attaching it to a minimal test scene in isolation\n",{"name":5,"description":7},"master","d7b26cdb5fae14d4ef7b713c5bf259395e75c3c6","skills\u002Fcomponent-system",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":49,"prompt":59,"zipAvailable":60},[50,53,56],{"tool":51,"command":52},"npx","npx skills add jame581\u002FGodotPrompter --skill component-system",{"tool":54,"command":55},"bunx","bunx skills add jame581\u002FGodotPrompter --skill component-system",{"tool":57,"command":58},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill component-system","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fcomponent-system\u002FSKILL.md",true,[],[63,83,104,129,145,163],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":34},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[70,71,33,72,73,74,75,76,77,78,79,27,80,81,82],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":34},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[90,91,92,93,94,95,96,97,27,33,73,98,99,100,101,102,103],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":34},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[],[91,111,112,113,114,115,116,117,99,118,119,33,120,121,122,123,124,125,27,126,127,128],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":133,"categories":134,"keywords":135,"publishedAt":34},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[],[73,136,137,138,139,27,140,141,142,143,144],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":146,"name":147,"nameZh":6,"description":148,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":149,"categories":150,"keywords":151,"publishedAt":34},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[152,153,27,154,155,156,157,158,159,160,161,33,162],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","common","implementing","sequences",{"skillNo":164,"name":165,"nameZh":6,"description":166,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":167,"categories":168,"keywords":169,"publishedAt":34},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[170,171,172,73,33,29,26,173,174,175,138,27,161,176],"state","state machine","machine","fsm","state machines","trade","trade-offs"]