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

/save-load

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

Use when building or replacing a save/load system — ConfigFile, JSON, Resource serialization, and save game architecture

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/save-load

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencessave-architecture.md

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

Save Architecture Pattern

Reference for skills/save-load/SKILL.md — SaveableComponent per-node pattern with Callable-based save/restore hooks.

← Back to SKILL.md


4. Save Architecture Pattern

For complex games, use the "saveable" group pattern. SaveManager collects serialized data from all registered nodes on save, then distributes data back to them on load.

SaveManager.save_game()
    │
    ├─► get_nodes_in_group("saveable")
    │       └─► node.serialize.call()  →  { id, data }
    │
    └─► write combined dict to disk

SaveManager.load_game()
    │
    ├─► read dict from disk
    │
    └─► get_nodes_in_group("saveable")
            └─► node.deserialize.call(data[node.id])

SaveableComponent Pattern

Add this component to any node that needs to participate in saving.

GDScript (saveable_component.gd)

# Attach to any node that should save/load its own state.
class_name SaveableComponent
extends Node

## Unique stable ID for this saveable object (set in the Inspector).
@export var save_id: String = ""

## Assign a Callable that returns a Dictionary of state to save.
var serialize: Callable = func() -> Dictionary:
	push_error("SaveableComponent: serialize not set on '%s'" % get_parent().name)
	return {}

## Assign a Callable that accepts a Dictionary to restore state from.
var deserialize: Callable = func(_data: Dictionary) -> void:
	push_error("SaveableComponent: deserialize not set on '%s'" % get_parent().name)


func _ready() -> void:
	add_to_group("saveable")

Example — Chest node using SaveableComponent:

# chest.gd
extends Node3D

@onready var saveable: SaveableComponent = $SaveableComponent

var is_open: bool = false
var contents: Array = ["sword", "potion"]


func _ready() -> void:
	saveable.serialize   = _serialize
	saveable.deserialize = _deserialize


func _serialize() -> Dictionary:
	return {"is_open": is_open, "contents": contents.duplicate()}


func _deserialize(data: Dictionary) -> void:
	is_open  = data["is_open"]
	contents = data["contents"].duplicate()
	if is_open:
		_play_open_animation()

C# (SaveableComponent.cs)

In C#, prefer Action/Func delegates over Callable for save/load hooks — they are type-safe at compile time and avoid the Callable.From() boilerplate. Use Callable.From() only when the hook needs to cross the GDScript ↔ C# boundary.

// Attach to any node that should save/load its own state.
using Godot;
using System;

public partial class SaveableComponent : Node
{
    /// <summary>Unique stable ID for this saveable object (set in the Inspector).</summary>
    [Export] public string SaveId = "";

    /// <summary>Assign a Func that returns a Dictionary of state to save.</summary>
    public Func<Godot.Collections.Dictionary> Serialize = () =>
    {
        GD.PushError("SaveableComponent: Serialize not set");
        return new Godot.Collections.Dictionary();
    };

    /// <summary>Assign an Action that accepts a Dictionary to restore state from.</summary>
    public Action<Godot.Collections.Dictionary> Deserialize = _ =>
    {
        GD.PushError("SaveableComponent: Deserialize not set");
    };

    public override void _Ready()
    {
        AddToGroup("saveable");
    }
}

Example — Chest node using SaveableComponent (C#):

// Chest.cs
using Godot;
using Godot.Collections;

public partial class Chest : Node3D
{
    [Export] public SaveableComponent Saveable;

    private bool _isOpen = false;
    private Array _contents = new Array { "sword", "potion" };

    public override void _Ready()
    {
        Saveable.Serialize = () => new Dictionary
        {
            { "is_open", _isOpen },
            { "contents", _contents.Duplicate() },
        };

        Saveable.Deserialize = data =>
        {
            _isOpen   = (bool)data["is_open"];
            _contents = (Array)((Array)data["contents"]).Duplicate();
            if (_isOpen)
                PlayOpenAnimation();
        };
    }

    private void PlayOpenAnimation() { /* ... */ }
}

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.

1 warning7d3 checks · Risk MEDIUM
  • Gen Agent Trust Hub7d

    This skill provides templates for Godot save/load systems. It includes a security warning regarding the risks of loading Godot Resource files (.tres/.res). However, the recommended JSON implementation contains a vulnerability where it loads and instantiates resource paths directly from the user-writable save data, which could allow a malicious save file to execute arbitrary internal resources or scripts.

  • 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/save-load