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

/resource-pattern

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

Use when creating data containers in Godot — custom Resources for configuration, items, stats, and editor integration

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/resource-pattern

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencessharing-vs-unique.md

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

Sharing vs Unique Resources

Reference for skills/resource-pattern/SKILL.md — when Resources share state vs .duplicate() for unique copies (v1.6.0 C# parity preserved).

← Back to SKILL.md


8. Sharing vs Unique

Resources loaded from the same path are shared. Every node that loads res://data/enemies/goblin.tres gets the exact same object in memory.

# Both variables point to the same object — modifying one modifies the other.
var a: EnemyStats = load("res://data/enemies/goblin.tres")
var b: EnemyStats = load("res://data/enemies/goblin.tres")
print(a == b)  # true

For per-instance mutable state, call duplicate():

func _ready() -> void:
    # Shallow duplicate — nested Resources are still shared
    stats = stats.duplicate()

    # Deep duplicate — nested sub-resources are copied too, with limits (below)
    stats = stats.duplicate(true)
public partial class Enemy : CharacterBody3D
{
    [Export] public EnemyStats StatsTemplate { get; set; }
    private EnemyStats _stats;

    public override void _Ready()
    {
        // Shallow duplicate — referenced sub-resources still point at the original.
        _stats = (EnemyStats)StatsTemplate.Duplicate();

        // Deep duplicate — sub-resources are also duplicated. Use only when needed (cost scales).
        // _stats = (EnemyStats)StatsTemplate.Duplicate(true);

        _stats.CurrentHealth = _stats.MaxHealth;
    }
}

duplicate() (Duplicate() in C#) returns a new Resource with the same property values. The original .tres file is untouched.

Deep-copy limits differ by version. On Godot 4.3, duplicate(true) never copies Resources held inside Array or Dictionary properties. On 4.7, it copies only embedded (built-in) sub-resources; ones saved to their own file stay shared unless you call duplicate_deep(Resource.DEEP_DUPLICATE_ALL).

Make Unique in the editor: In the Inspector, any sub-resource slot shows a Make Unique button. Clicking it embeds a private copy of the sub-resource into the parent scene instead of referencing the shared file. Use this when one scene needs different values than the shared default.

Guideline:

  • Read-only data (item definitions, level config) — share freely, no duplication needed.
  • Mutable runtime state (current health, active buffs) — always duplicate() in _ready().

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

    This skill provides standard design patterns for Godot engine development using the Resource class for data storage and configuration. It includes clear documentation on best practices and specifically warns users about the security risks associated with loading resource files from untrusted sources.

  • 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 month

README badge

README badge for jame581/godotprompter/resource-pattern