Index of every page on this site: llms.txt
All skills
jame581 avatar

/dependency-injection

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when choosing how systems get their dependencies — autoloads, service locators, @export injection, and scene injection patterns

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/dependency-injection

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesexport-injection.md

≈654 tokens on demand. Your agent reads this file only when SKILL.md points to it.

@export Node Injection

Reference for skills/dependency-injection/SKILL.md — exposing dependencies as @export properties for Inspector wiring. GDScript + C#.

← Back to SKILL.md


4. @export Node Injection

The most Godot-idiomatic DI pattern. Declare a dependency as @export and wire it in the editor Inspector — or assign it from a parent in code. The node never needs to know where its dependency lives in the tree.

This is preferred over get_node("../../SomeNode") hard-coded paths, which fail at runtime with Node not found when the scene tree is reorganised.

GDScript

# health_component.gd — receives its audio dependency via @export
class_name HealthComponent
extends Node

@export var audio: AudioService          ## Set in the Inspector or by parent
@export var max_health: int = 100

var current_health: int


func _ready() -> void:
    current_health = max_health


func take_damage(amount: int) -> void:
    current_health = clampi(current_health - amount, 0, max_health)
    # Uses the injected reference — no direct autoload access
    if audio != null:
        audio.play_sfx("hurt")
    health_changed.emit(current_health, max_health)
    if current_health == 0:
        died.emit()


signal health_changed(current: int, maximum: int)
signal died
# player.gd — wires the component in the editor or in _ready()
extends CharacterBody2D

@export var health: HealthComponent      ## Drag HealthComponent node here in Inspector

C#

using Godot;

/// <summary>
/// Reusable health component. Wire dependencies via the Inspector.
/// </summary>
public partial class HealthComponent : Node
{
    [Export] public AudioService Audio { get; set; }   // Set in Inspector or by parent
    [Export] public int MaxHealth { get; set; } = 100;

    [Signal] public delegate void HealthChangedEventHandler(int current, int maximum);
    [Signal] public delegate void DiedEventHandler();

    private int _currentHealth;

    public override void _Ready()
    {
        _currentHealth = MaxHealth;
    }

    public void TakeDamage(int amount)
    {
        _currentHealth = Mathf.Clamp(_currentHealth - amount, 0, MaxHealth);
        Audio?.PlaySfx("hurt");
        EmitSignal(SignalName.HealthChanged, _currentHealth, MaxHealth);
        if (_currentHealth == 0)
            EmitSignal(SignalName.Died);
    }
}
using Godot;

public partial class Player : CharacterBody2D
{
    // Drag HealthComponent node here in the Inspector
    [Export] public HealthComponent Health { get; set; }
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides safe architectural guidance and code examples for dependency injection patterns in Godot 4.3+, using standard GDScript and C# practices.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last week

README badge

README badge for jame581/godotprompter/dependency-injection