Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when building reusable node components — composition patterns, component communication, and interface design
.claude/skills/jame581-component-system/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 31% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 77% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 127% | 0% |
| case-21 | ✗→✓ | ▲ Improved | 92% | 0% |
| case-06 | ✓→✗ | ▼ Worse | 166% | 0% |
Build 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.
> 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/3D overlap detection and collision shapes, ability-system for an AbilityComponent example built on this pattern.
| Problem with inheritance | How components solve it | |--------------------------|-------------------------| | Deep chains are brittle — change one class, break many | Each component is an isolated scene with a single job | | Sharing behavior across unrelated entities requires awkward base classes | Drop a component onto any entity that needs that behavior | | Adding a new combination means a new subclass | Mix and match components freely at the scene level |
Key benefits:
HealthComponent works on a player, an enemy, a destructible crate, or a boss with no code changes.HitboxComponent and a PatrolComponent independently. Removing one does not affect the other.HealthAndShieldAndRegenComponent, split it.get_parent().get_node("SiblingComponent"). Emit a signal instead.@export configuration over storing mutable state. When state is necessary, keep it private.@export for all configuration. Damage amount, cooldown duration, and layer masks belong in the Inspector, not hardcoded constants.| Component | Purpose | Key Signals | |---|---|---| | HealthComponent | Tracks current and max HP, applies damage and healing | health_changed(current, maximum), died | | HitboxComponent | Detects overlapping hurtboxes and triggers damage | hit(target_hurtbox) | | HurtboxComponent | Receives hits, routes damage to HealthComponent | hurt(damage_amount) | | InteractableComponent | Marks an entity as interactable and fires on player overlap | interacted(interactor) | | StateMachineComponent | Delegates _process and _physics_process to child state nodes | state_changed(from, to) |
Attach to any entity that deals damage. Configure damage in the Inspector.
hitbox_component.gd)gdscriptclass_name HitboxComponent extends Area2D ## Damage dealt to the target hurtbox on contact. @export var damage: int = 10 ## Minimum seconds between successive hits (0 = no cooldown). @export var cooldown_duration: float = 0.5 signal hit(target_hurtbox: HurtboxComponent) var _on_cooldown: bool = false @onready var _cooldown_timer: Timer = _build_timer() func _ready() -> void: area_entered.connect(_on_area_entered) func _on_area_entered(area: Area2D) -> void: if _on_cooldown: return if area is not HurtboxComponent: return hit.emit(area) area.receive_hit(damage) if cooldown_duration > 0.0: _on_cooldown = true _cooldown_timer.start(cooldown_duration) func _on_cooldown_timeout() -> void: _on_cooldown = false func _build_timer() -> Timer: var t := Timer.new() t.one_shot = true t.timeout.connect(_on_cooldown_timeout) add_child(t) return t
HitboxComponent.cs)csharpusing Godot; public partial class HitboxComponent : Area2D { /// <summary>Damage dealt to the target hurtbox on contact.</summary> [Export] public int Damage { get; set; } = 10; /// <summary>Minimum seconds between successive hits (0 = no cooldown).</summary> [Export] public float CooldownDuration { get; set; } = 0.5f; [Signal] public delegate void HitEventHandler(HurtboxComponent targetHurtbox); private bool _onCooldown; private Timer _cooldownTimer; public override void _Ready() { _cooldownTimer = new Timer { OneShot = true }; _cooldownTimer.Timeout += OnCooldownTimeout; AddChild(_cooldownTimer); AreaEntered += OnAreaEntered; } private void OnAreaEntered(Area2D area) { if (_onCooldown) return; if (area is not HurtboxComponent hurtbox) return; EmitSignal(SignalName.Hit, hurtbox); hurtbox.ReceiveHit(Damage); if (CooldownDuration > 0f) { _onCooldown = true; _cooldownTimer.Start(CooldownDuration); } } private void OnCooldownTimeout() => _onCooldown = false; }
Attach to any entity that can take damage. Wire it to a sibling HealthComponent via @export.
hurtbox_component.gd)gdscriptclass_name HurtboxComponent extends Area2D ## Reference to the HealthComponent on the same entity. @export var health_component: HealthComponent ## Invincibility frame duration in seconds (0 = none). @export var invincibility_duration: float = 0.0 signal hurt(damage_amount: int) var _invincible: bool = false @onready var _iframes_timer: Timer = _build_timer() func receive_hit(damage: int) -> void: if _invincible: return hurt.emit(damage) if health_component: health_component.take_damage(damage) if invincibility_duration > 0.0: _invincible = true _iframes_timer.start(invincibility_duration) func _on_iframes_timeout() -> void: _invincible = false func _build_timer() -> Timer: var t := Timer.new() t.one_shot = true t.timeout.connect(_on_iframes_timeout) add_child(t) return t
HurtboxComponent.cs)csharpusing Godot; public partial class HurtboxComponent : Area2D { /// <summary>Reference to the HealthComponent on the same entity.</summary> [Export] public HealthComponent HealthComponent { get; set; } /// <summary>Invincibility frame duration in seconds (0 = none).</summary> [Export] public float InvincibilityDuration { get; set; } = 0f; [Signal] public delegate void HurtEventHandler(int damageAmount); private bool _invincible; private Timer _iframesTimer; public override void _Ready() { _iframesTimer = new Timer { OneShot = true }; _iframesTimer.Timeout += OnIframesTimeout; AddChild(_iframesTimer); } public void ReceiveHit(int damage) { if (_invincible) return; EmitSignal(SignalName.Hurt, damage); HealthComponent?.TakeDamage(damage); if (InvincibilityDuration > 0f) { _invincible = true; _iframesTimer.Start(InvincibilityDuration); } } private void OnIframesTimeout() => _invincible = false; }
Components must not call methods on siblings directly. Use signals to keep them decoupled.
┌─────────────────────────────────────────────────────┐
│ Entity (CharacterBody2D) │
│ │
│ ┌──────────────┐ hit(hurtbox) │
│ │ HitboxComponent ──────────────────────────────┐ │
│ └──────────────┘ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ HurtboxComponent │ │
│ │ receive_hit(dmg) │ │
│ │ ──── calls ──────► │ │
│ │ HealthComponent │ │
│ │ .take_damage(dmg) │ │
│ └────────┬────────────┘ │
│ │ │
│ health_changed / died │
│ │ │
│ ┌────────▼────────────┐ │
│ │ HealthComponent │ │
│ │ emits: died │ │
│ └─────────────────────┘ │
└─────────────────────────────────────────────────────┘Flow explained:
HitboxComponent detects an overlapping HurtboxComponent via area_entered.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.HurtboxComponent.receive_hit() emits hurt(damage_amount) for animation/VFX, then calls health_component.take_damage(damage) on its explicitly wired reference.HealthComponent.take_damage() updates HP and emits health_changed or died. Listeners (UI, GameManager, etc.) connect to those signals without touching the combat components.Three patterns in order of preference:
gdscript# hurtbox_component.gd @export var health_component: HealthComponent # Inspector: drag the HealthComponent node into the slot.
> Gotcha: @export node references are wired via the editor inspector. If you build scenes programmatically or hand-write .tscn files, the reference may be null at runtime. In that case, wire it explicitly in the parent's _ready(): > gdscript > hurtbox.health_component = health_component >
gdscript# enemy.gd @onready var health: HealthComponent = $HealthComponent @onready var hurtbox: HurtboxComponent = $HurtboxComponent
gdscriptfunc _ready() -> void: var health := get_node_or_null("HealthComponent") as HealthComponent if health: health.died.connect(_on_died)
> 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.
csharp// Pattern 1: [Export] property — drag-and-drop in the Inspector. public partial class HurtboxComponent : Area3D { [Export] public HealthComponent Health { get; set; } } // Pattern 2: GetNode<T> for a known child path (equivalent to @onready var x := $Path). public partial class Enemy : CharacterBody3D { private HealthComponent _health; private HurtboxComponent _hurtbox; public override void _Ready() { _health = GetNode<HealthComponent>("HealthComponent"); _hurtbox = GetNode<HurtboxComponent>("HurtboxComponent"); _health.Died += QueueFree; } } // Pattern 3: GetNodeOrNull<T> when the component is optional (equivalent to get_node_or_null). public partial class Pickup : Node3D { public override void _Ready() { var health = GetNodeOrNull<HealthComponent>("HealthComponent"); if (health != null) health.Died += OnDied; } private void OnDied() { /* ... */ } }
Use a static utility to locate the first component of a given type on any entity. This avoids hardcoding node names across different entity scenes.
component_utils.gd)gdscriptclass_name ComponentUtils ## Returns the first child of [param entity] that is an instance of [param component_type], ## or null if none is found. static func get_component(entity: Node, component_type: GDScript) -> Node: for child in entity.get_children(): if is_instance_of(child, component_type): return child return null ## Example usage: ## var health := ComponentUtils.get_component(enemy, HealthComponent) as HealthComponent ## if health: ## health.take_damage(5)
ComponentUtils.cs)csharpusing Godot; public static class ComponentUtils { /// <summary> /// Returns the first child of <paramref name="entity"/> that is of type /// <typeparamref name="T"/>, or null if none is found. /// </summary> public static T GetComponent<T>(Node entity) where T : Node { foreach (var child in entity.GetChildren()) { if (child is T component) return component; } return null; } } // Example usage: // var health = ComponentUtils.GetComponent<HealthComponent>(enemy); // health?.TakeDamage(5);
.tscn scene and reused by instancingget_parent().get_node("Sibling") callsdamage, max_health, cooldown_duration) are @export| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 21,772 | 10,921 | -50% | 1 | 1 | 0% | 4,286 | 5,627 | +31% | 0 | 0 | — |
case-02 | fail→pass | 18,541 | 14,959 | -19% | 1 | 1 | 0% | 3,633 | 6,438 | +77% | 0 | 0 | — |
case-03 | fail→fail | 22,206 | 15,084 | -32% | 1 | 1 | 0% | 4,218 | 6,614 | +57% | 0 | 0 | — |
case-04 | pass→pass | 12,217 | 13,970 | +14% | 1 | 1 | 0% | 2,216 | 6,041 | +173% | 0 | 0 | — |
case-05 | pass→pass | 11,356 | 8,286 | -27% | 1 | 1 | 0% | 2,187 | 4,802 | +120% | 0 | 0 | — |
case-06 | pass→fail | 11,998 | 10,852 | -10% | 1 | 1 | 0% | 2,016 | 5,369 | +166% | 0 | 0 | — |
case-07 | pass→fail | 16,770 | 15,337 | -9% | 1 | 1 | 0% | 2,869 | 6,160 | +115% | 0 | 0 | — |
case-08 | pass→pass | 13,550 | 10,310 | -24% | 1 | 1 | 0% | 2,154 | 5,176 | +140% | 0 | 0 | — |
case-09 | pass→pass | 17,504 | 16,699 | -5% | 1 | 1 | 0% | 3,091 | 6,266 | +103% | 0 | 0 | — |
case-10 | fail→fail | 8,829 | 4,827 | -45% | 1 | 1 | 0% | 1,473 | 4,229 | +187% | 0 | 0 | — |
case-11 | fail→pass | 12,834 | 8,874 | -31% | 1 | 1 | 0% | 2,357 | 5,359 | +127% | 0 | 0 | — |
case-12 | pass→pass | 12,265 | 6,583 | -46% | 1 | 1 | 0% | 1,905 | 4,447 | +133% | 0 | 0 | — |
case-13 | pass→pass | 12,019 | 7,732 | -36% | 1 | 1 | 0% | 1,824 | 4,822 | +164% | 0 | 0 | — |
case-14 | pass→pass | 12,536 | 6,681 | -47% | 1 | 1 | 0% | 2,370 | 4,717 | +99% | 0 | 0 | — |
case-15 | pass→pass | 15,567 | 16,410 | +5% | 1 | 1 | 0% | 2,572 | 6,387 | +148% | 0 | 0 | — |
case-16 | pass→pass | 17,289 | 15,271 | -12% | 1 | 1 | 0% | 2,947 | 6,381 | +117% | 0 | 0 | — |
case-17 | fail→fail | 16,679 | 9,712 | -42% | 1 | 1 | 0% | 2,953 | 5,042 | +71% | 0 | 0 | — |
case-18 | pass→pass | 13,959 | 10,289 | -26% | 1 | 1 | 0% | 2,258 | 5,232 | +132% | 0 | 0 | — |
case-19 | pass→pass | 11,249 | 5,971 | -47% | 1 | 1 | 0% | 1,916 | 4,327 | +126% | 0 | 0 | — |
case-20 | fail→fail | 14,286 | 11,509 | -19% | 1 | 1 | 0% | 2,417 | 5,454 | +126% | 0 | 0 | — |
case-21 | fail→pass | 14,114 | 7,386 | -48% | 1 | 1 | 0% | 2,459 | 4,714 | +92% | 0 | 0 | — |
case-22 | pass→pass | 15,624 | 12,223 | -22% | 1 | 1 | 0% | 2,599 | 5,646 | +117% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases. 2 cases got worse with the skill loaded, and they are included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.