Skip to content

77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.

fix(save-systems): checked Godot 4.7 atomic save and .bak fallback, JSON number and object-loading pitfalls, save locations and Steam Cloud

Kiro Crewb29cd9cedca9
diff --git a/skills/disciplines/save-systems/SKILL.md b/skills/disciplines/save-systems/SKILL.md
index 1218ea1..dbfa017 100644
--- a/skills/disciplines/save-systems/SKILL.md
+++ b/skills/disciplines/save-systems/SKILL.md
@@ -74,21 +74,38 @@ func apply_state(data: Dictionary) -> void:
### 2. Atomic, crash-safe write (temp + rename)
```gdscript
-# RIGHT: write to a temp file, then atomically rename over the target.
-func save_atomic(path: String, data: Dictionary) -> void:
+# Godot 4.7. Write a temp file, keep the previous save as .bak, then rename.
+func save_atomic(path: String, data: Dictionary) -> Error:
var tmp := path + ".tmp"
var f := FileAccess.open(tmp, FileAccess.WRITE)
- f.store_string(JSON.stringify(data))
- f.flush() # ensure bytes hit disk
- f.close()
- DirAccess.rename_absolute(tmp, path) # replaces the target; atomic on POSIX
+ if f == null:
+ return FileAccess.get_open_error() # disk full, read-only, no permission...
+ if not f.store_string(JSON.stringify(data)):
+ return ERR_FILE_CANT_WRITE
+ f.close() # flushes Godot's buffer to the OS
+ if FileAccess.file_exists(path):
+ DirAccess.rename_absolute(path, path + ".bak") # keep the last good save
+ return DirAccess.rename_absolute(tmp, path)
+
+func load_save(path: String) -> Dictionary: # empty = nothing loadable
+ for p in [path, path + ".bak"]: # .bak covers a crash between renames
+ if FileAccess.file_exists(p):
+ var data = JSON.parse_string(FileAccess.get_file_as_string(p))
+ if data is Dictionary and data.has("version"):
+ data["version"] = int(data["version"]) # JSON numbers load as float
+ return data
+ return {}
# WRONG: opening `path` directly and writing in place — a crash mid-write leaves a
# truncated, unloadable save and destroys the player's progress.
```
-Rename-over-target is atomic on POSIX (same volume); on Windows a replace-by-rename
-isn't guaranteed atomic, so keep the previous file as `path + ".bak"` before the
-rename — that backup is what actually guarantees you can recover from a bad write.
+A crash now leaves the old save, the new one, or (between the two renames) only
+the `.bak` — which the loader tries next. Two limits to know: `rename()` replaces
+the target atomically on POSIX (same volume), but Godot's Windows `rename_absolute`
+deletes the target and then moves, so that platform relies on the `.bak` too; and
+neither `flush()` nor `close()` calls `fsync`, so a power cut right after a save
+can still lose the newest file. Check the returned `Error` and tell the player
+when a save fails instead of carrying on.
### 3. Versioned load with migration
@@ -97,7 +114,7 @@ SAVE_VERSION = 3
def load_save(raw_bytes):
data = parse(raw_bytes) # JSON/binary -> dict
- v = data.get("version", 0)
+ v = int(data.get("version", 1)) # no field = the first shipped schema
if v > SAVE_VERSION:
raise NewerSaveError(v) # save is from a newer build; refuse
while v < SAVE_VERSION: # apply migrations in order, v -> v+1
@@ -111,6 +128,9 @@ def load_save(raw_bytes):
def migrate_1_to_2(d):
d["flags"] = {k: True for k in d.pop("completed_quests", [])} # list -> set-map
return d
+def migrate_2_to_3(d):
+ d.setdefault("difficulty", "normal") # new field: old saves get the default
+ return d
MIGRATIONS = {1: migrate_1_to_2, 2: migrate_2_to_3}
```
@@ -141,6 +161,15 @@ func autosave_if_due(dt: float) -> void:
cloud-synced stale. Validate on load and fall back to backup on failure.
- **Floats and locale.** Text serializers can drop precision or use comma
decimal separators in some locales. Use a locale-invariant serializer.
+- **Godot JSON turns every number into a float**: `version` 3 loads as `3.0`,
+ so `migrations.has(data["version"])` is false and integers above 2^53 (64-bit
+ IDs, big seeds) lose digits. Convert with `int()` on load, store IDs as
+ strings, or wrap the state in `JSON.from_native()` / `JSON.to_native()`, which
+ round-trip `int`, `Vector2` and other engine types exactly.
+- **Loading objects from save files.** Godot `str_to_var`/`get_var` with objects
+ allowed, a `ConfigFile` that stores objects, or `ResourceLoader` on a `.tres`
+ the player can swap will instantiate an object with a script attached, and that
+ script runs during the load. Saves get shared online; keep them plain data.
- **Autosave clobbering manual saves**, or firing mid-action and saving an
inconsistent state. Use a dedicated autosave slot and save on safe boundaries.
- **Storing secrets or trusting client saves in multiplayer.** A local save is
@@ -150,8 +179,9 @@ func autosave_if_due(dt: float) -> void:
## References
- `references/versioning-and-migration.md` — schema evolution strategies, the
- migration chain, backups/rollback, format trade-offs (JSON vs binary), and a
- load-time validation checklist.
+ migration chain, backups/rollback, format trade-offs (JSON vs binary), a
+ load-time validation checklist, and where saves live per engine plus Steam
+ Cloud setup.
## Related skills
diff --git a/skills/disciplines/save-systems/references/versioning-and-migration.md b/skills/disciplines/save-systems/references/versioning-and-migration.md
index f39064e..c1d3bd4 100644
--- a/skills/disciplines/save-systems/references/versioning-and-migration.md
+++ b/skills/disciplines/save-systems/references/versioning-and-migration.md
@@ -86,6 +86,45 @@ that neutral shape, not on format-specific bytes.
- On any failure: log, fall back to backup, and if all else fails, fail *loudly*
to the player rather than silently loading a broken state.
+## Where saves live, and cloud sync
+
+Write saves to the per-user data folder the engine gives you, never next to the
+executable (often read-only, and replaced by updates):
+
+- **Godot 4.7** `user://` — Windows `%APPDATA%\Godot\app_userdata\[project]`,
+ macOS `~/Library/Application Support/Godot/app_userdata/[project]`, Linux
+ `~/.local/share/godot/app_userdata/[project]`. Turn on
+ `application/config/use_custom_user_dir` (optionally with
+ `custom_user_dir_name`) to drop the `Godot/app_userdata` part before you ship,
+ because changing it later moves every player's saves. Web exports store
+ `user://` in the browser's IndexedDB.
+- **Unity 6.3** `Application.persistentDataPath` — Windows
+ `%userprofile%\AppData\LocalLow\<company>\<product>`, Linux
+ `~/.config/unity3d/<company>/<product>`, macOS player
+ `~/Library/Application Support/unity.<company>.<product>`; Web uses IndexedDB;
+ tvOS returns an empty string (no persistent folder). Changing the company or
+ product name changes the folder.
+- **Unreal 5.8** `UGameplayStatics::SaveGameToSlot` / `AsyncSaveGameToSlot`
+ with a `USaveGame` subclass; the platform layer picks the folder and, on
+ consoles, the platform save API.
+
+**Steam Cloud.** Auto-Cloud syncs files under the root paths you configure in
+Steamworks (for example `WinAppDataRoaming`, `WinAppDataLocalLow`,
+`MacAppSupport`, `LinuxXdgDataHome`); the ISteamRemoteStorage API is the
+alternative when you need control. Files upload after the game exits and
+download before the next launch, so a save written while the game runs is not
+in the cloud yet. Choose the Cross-Platform OS setting for each root (with root
+overrides where the folder differs per OS) even for a single-platform game: a
+root locked to one OS will not sync to other platforms if you add them later.
+Set the per-user byte and file quotas in the app admin panel first; Steam Cloud
+is not active without them. Keep the `.tmp` file out of the synced pattern.
+Games that opt into Dynamic Cloud Sync (Steam Deck suspend) can receive changed
+files mid-session and must reload them.
+
+**Consoles and mobile** have platform save APIs, storage limits and
+certification rules; follow the platform's documentation rather than raw file
+paths there.
+
## What to store vs recompute
- **Store** authoritative, non-derivable state: choices, unlocked flags, RNG