saves
Skill1 starsChanged 2 days agoApache-2.0View on GitHub
Use when a Godot game saves progress, settings or profiles, when a save format changes between versions, when saves are synced through Steam Cloud or another cloud, or when a save went missing, corrupt or was lost after an update.
In this repository56 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- algorithmsSkill
- animationSkill
- anti-cheatSkill
- asset-pipelineSkill
- automation-hooksSkill
- calendarSkill
- cameraSkill
- console-certSkill
- debug-toolsSkill
- determinismSkill
- game-aiSkill
- game-audioSkill
- game-dataSkill
- game-designSkill
- game-juiceSkill
- game-planSkill
- game-playtestSkill
- gameSkill
- game-telemetrySkill
- godot-addonsSkill
- godot-diagnoseSkill
- godot-editor-bridgeSkill
- godot-export-releaseSkill
- godot-pitfallsSkill
- godot-shaders-vfxSkill
- godot-test-loopSkill
- inputSkill
- kit-reviewSkill
- kitSkill
- legalSkill
- llmSkill
- localizationSkill
- lookSkill
- mathSkill
- mobile-webSkill
- moddingSkill
- multiplayerSkill
- narrativeSkill
- new-gameSkill
- patternsSkill
- performanceSkill
- procgenSkill
- progressionSkill
- release-readinessSkill
- retroSkill
- serversSkill
- steamSkill
- store-pageSkill
- typographySkill
- ui-accessibilitySkill
- ui-flowsSkill
- verify-before-doneSkill
- weekly-reviewSkill
- xrSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Not with FileAccess. FileAccess.Open(path, Write) truncates the live save first and Flush() only reaches the OS, never the disk: a crash or …
- Very specific: line 18
Use System.IO on the real path: ProjectSettings.GlobalizePath("user://saves/slot1.json").
- Very specific: line 34
Never ResourceSaver/.tres, var_to_str/str_to_var, get_var(true) or BinaryFormatter.
- Very specific: line 56
put that copy back as the save and keep the damaged file as slot.json.corrupt-<time>.
- Distinctive: line 76
Write a migrated save back at the current version on the next normal save, not during the load.
- Very specific: line 77
When a version ships, commit one real save from it as a golden file (tests/.../Saves/golden/v3.json).
- Distinctive: line 90
Keep the rules between choices as data (a hero who died had no child), with a test that each can be met.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Save systems in Godot 4 (C#)
A save must survive a crash in the middle of writing, a disk that flips a bit, the next five versions of the game and a
second device. The working, tested version is ${CLAUDE_PLUGIN_ROOT}/examples/csharp/src/Example.Core/Saves/SaveStore.cs
(plain .NET, no engine) with its tests in ${CLAUDE_PLUGIN_ROOT}/examples/csharp/tests/Example.Core.Tests/SaveStoreTests.cs; copy it unchanged,
pass the game's own format name (new SaveStore(path, currentVersion, migrations, "mygame-save")) and change the schema. Sources and the measurements behind each rule: ${CLAUDE_PLUGIN_ROOT}/docs/saves.md.
1. Where and with what to write
- Not with
FileAccess.FileAccess.Open(path, Write)truncates the live save first andFlush()only reaches the OS, never the disk: a crash or power cut mid-write leaves no save at all. Godot's own write-then-rename is switched on only in the editor.DirAccess.Renameon Windows deletes the target before moving, which has the same hole. - Use
System.IOon the real path:ProjectSettings.GlobalizePath("user://saves/slot1.json"). - Pin
application/config/use_custom_user_dirandcustom_user_dir_namebefore the first release.user://is named after the project name otherwise, so renaming the game moves (loses) every player's saves. - Saves and settings are separate files. Settings (resolution, volume) are per device and stay out of the cloud.
- C# games cannot export to the web in Godot 4, so
user://is always a real folder. - Kit runs must not read or write the player's save: tests, flows,
shot,clip,audio -Mix,soakandexport -Runof a release build all run the game on the owner's machine. Every program the kit starts hasHYPERDOT_RUN=1in its environment: whenOS.GetEnvironment("HYPERDOT_RUN") == "1", save to a throwaway folder (or not at all) and load nothing. It reachesdotnet testand release builds, where--no-saveand the engine's own flags do not.
2. Format: plain data only
- JSON with
System.Text.Json. Migrate onJsonNode(section 4), then deserialize into typed records with a source-generatedJsonSerializerContext. iOS exports are NativeAOT (trimmed), where reflection-based JSON fails at run time; set<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>in the.csprojso desktop builds fail the same way, early. - Never
ResourceSaver/.tres,var_to_str/str_to_var,get_var(true)orBinaryFormatter. Loading a.tresorstr_to_vartext runs a script embedded in it (tested on 4.7.2), and players trade save files.BinaryFormatterthrows on .NET 8. - Wrap the data in an envelope: format name,
version, agenerationcounter, save time (for display only), play time, and a SHA-256 checksum over everything else. The checksum catches truncation and flipped bits; it does not stop a player editing the file (the key would ship in the game), and it is not anti-cheat.
3. Writing and reading without losing anything
write slot.json.tmp -> Flush(flushToDisk: true) -> File.Replace(tmp, slot.json, slot.json.bak) (File.Move for the first save)
-> fsync the folder (Linux)Flush(true)is fsync /FlushFileBuffers. PlainFlush()andDispose()are not durable.File.Replacethrows when the save does not exist yet: first save withFile.Move.- On Windows, antivirus and cloud-sync clients hold files for a moment: retry a few times on
IOException(Godot's editor retries 1000 times). - A crash can leave any of: a partial
.tmp, a complete.tmpnever swapped in, no.bak, or (Windows error 1177) no save with the old one as.bakand the new one as.tmp. Load like this:- the save, if it passes its checksum and is not from a newer version; else
- the valid
.tmpor.bakwith the highergeneration(never the clock: clocks jump and devices disagree); - put that copy back as the save and keep the damaged file as
slot.json.corrupt-<time>. Skip this and the next save rotates the damaged file into.bak, losing the only good copy; - nothing valid: say so, keep every file, and never write a fresh save over the slot on your own.
- A valid save can still hold broken game state (a logic bug, not a disk error). Keep a few generations (
.bak1...bak3) or a copy per milestone for that.
4. Versions and migrations
public const int CurrentVersion = 3;
public static readonly IReadOnlyDictionary<int, Func<JsonObject, JsonObject>> Migrations = new Dictionary<int, Func<JsonObject, JsonObject>>
{
[1] = v1 => { var v2 = (JsonObject)v1.DeepClone(); v2["levelsCleared"] = 0; return v2; }, // v1 -> v2
[2] = v2 => new JsonObject { ["best"] = new JsonObject { ["score"] = v2["highScore"]?.GetValue<int>() ?? 0 } }, // v2 -> v3
};- One step per version, applied in order, kept forever. Refuse to start if a step is missing.
- A save from a newer version is neither loaded nor overwritten: tell the player to update. Xbox makes this a certification rule (XR-003: no permanent data loss when an updated save meets the base version).
- Write a migrated save back at the current version on the next normal save, not during the load.
- When a version ships, commit one real save from it as a golden file (
tests/.../Saves/golden/v3.json). CI loads every golden file through the real loader and checks the migrated values. Never regenerate an old golden file from the current build: that hides the migration you broke. - A save from before envelopes existed (v1) is recognised only with
bareVersionOne: trueand only when no envelope field is present, so a damaged envelope is never mistaken for an old save. A game that always wrote the envelope leaves it off: any other JSON at its save path then loads asCorruptand is left as it is.
Choices carried into a sequel or New Game+
Importing a whole old save broke for Dragon Age: dead characters came back, choices were overturned, and each fix needed a client patch. BioWare's Dragon Age Keep kept only the key choices, with the plot rules between them:
- Export the key choices to a small versioned file of their own, not the save; each game reads only the ones it uses.
- Keep the rules between choices as data (a hero who died had no child), with a test that each can be met.
- On import, validate; if rules conflict, repair to the nearest valid state (fewest choices changed) and show the player only what changed and why. Never refuse the whole file, and never trust it unchecked.
5. Two devices: cloud conflicts
Steam Cloud (and Epic, GOG) sync files at launch and exit; when both sides changed, Steam shows only file dates and advises "the most recently modified", which picks wrong when a clock is off or the player played offline on both. Decide in the game, the way git fast-forwards:
- Each save keeps the hashes of the last 32 saves it descends from (
CloudSync.Decidein the C# example). - Same hash: in sync. The cloud's hash is in the local history: local is newer, upload. The local hash is in the cloud's history: download. Neither: a real conflict.
- A conflict shows both sides with what players recognise: device, play time, progress (chapter, level, %), save time, and a thumbnail if cheap. Buttons "Keep this device" and "Keep cloud", focus on neither, and the loser copied to a spare slot, never discarded.
- A save service of your own (Open Saves' lessons): reject a write whose token from the last read no longer matches, instead of letting the later write win; raise a best score with compare-and-swap-greater on the server, never read-change-write from two devices; keep a few small queryable fields (slot name, level, play time) apart from the save itself, so a slot list loads without the saves.
- Steam Auto-Cloud: a root per OS where
user://lives and a pattern matching only the save files (*.json, not*.tmp,*.corrupt-*); the App Admin setup is insteamsection 5. On Steam Deck, Dynamic Cloud Sync uploads at suspend: wrap a multi-file save inBeginFileWriteBatch/EndFileWriteBatchand handleRemoteStorageLocalFileChange_t(via GodotSteam or Steamworks.NET).
6. Saving without the player noticing
- Snapshot the state on the main thread (plain records), serialize and write on a background
Task, show a small non-modal "saving" mark until it finishes. Never freeze: Xbox fails a game for a static screen over 20 seconds. - Finish a pending save before quitting: handle
NotificationWMCloseRequest(andNotificationApplicationPausedon Android), withGetTree().AutoAcceptQuit = falseuntil the write is done. - One save in flight per slot; a second request waits or replaces the pending snapshot.
7. Prove it
- golden saves for every shipped version load and migrate to the expected values (
godot-test-loop, plain xUnit like the C# example'sEveryShippedVersionLoadsAndMigrates) - truncating the save at every byte and flipping a bit at every byte never loads wrong data and never throws
- each crash state (partial tmp, unswapped tmp, missing save with tmp and bak, damaged save) loads the right copy, and after a recovery the next save still leaves a good backup
- a save from a newer version is refused and left byte-for-byte unchanged
- cloud decisions: same, ahead, behind and diverged lineages, including a clock set years ahead
- the bindings, settings and saves are three files; settings are not in the cloud's file pattern
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

