| Engine | Unity 2022.3 LTS or newer |
|---|---|
| Language | C# |
| Time to run | ~4 minutes |
| Level | Beginner — comfortable with C# classes and SerializeField |
| Output | One static class + one example SaveData struct, ~80 lines |
| Dependencies | None. PlayerPrefs and JsonUtility are built in. |
The prompt
Open claude.ai/new, paste, and send.
$ Build me a SaveSystem for Unity 2022.3+ that persists a SaveData class to PlayerPrefs as JSON. // shape - A static class SaveSystem with: Save(SaveData data), Load() → SaveData, Has() → bool, Delete(). - A serializable SaveData class with example fields: int level, float playtime, string lastScene, int version. - Use JsonUtility.ToJson and FromJson. Store under PlayerPrefs key "save_v1". // behavior - Load() returns a default SaveData if no key exists or JSON parse fails. - Save() always sets data.version to the current SCHEMA_VERSION constant before serializing. - A private Migrate(SaveData old) method handles version mismatches: returns a new SaveData with old fields copied where compatible, defaults elsewhere. - Logs a warning (not an exception) if migration is needed. // constraints - No try/catch swallowing all exceptions. Catch JsonException specifically. - No async / coroutines. Saves are synchronous, small, and rare. // return format - One file, named SaveSystem.cs. - Include the SaveData class in the same file. - No prose before or after the code.
What this gets you
The version-migration piece is the part that usually gets skipped in tutorials, and it's the part that breaks players' saves a year later when you add a new field. This prompt builds it in from the start, so adding a new SaveData field never costs anyone their progress.
Quick checklist
- SCHEMA_VERSION lives at the top. Bumping a number is the only thing you should need to do when changing the schema.
- Load() never throws on bad data. A corrupted save returns defaults plus a warning, not a crash.
- Migrate() does explicit copies, not reflection. Reflection-based migration is harder to debug and slower. Prefer 6 lines of explicit copying.
Full breakdown coming soon
This page is the prompt itself plus a minimal checklist. The deeper writeup with worked examples, common gotchas, and how to extend with binary encryption is on the roadmap. Bookmark this page or check back on the blog as it ships.