Skip to content

t1k:unity:base:save-system

FieldValue
Modulebase
Version2.2.2
Effortmedium
Tools

Keywords: data, persistence, save system, unity

/t1k:unity:base:save-system

Unity Save System — Persistence Patterns

Section titled “Unity Save System — Persistence Patterns”

Save system patterns for Unity 6. No built-in save framework — must implement.

string savePath = Application.persistentDataPath;
// Windows: AppData/LocalLow/<company>/<product>/
// iOS/Android: platform Documents/files dirs
// PlayerPrefs — settings ONLY, never game saves:
PlayerPrefs.SetInt("MusicVolume", 80);

→ See references/save-patterns.md for all platform paths, full paths per OS.

[System.Serializable]
public class SaveData {
public int version = 1; // For migration
public string timestamp;
public PlayerSaveData player;
public List<QuestSaveData> quests;
public WorldSaveData world;
}

Gotcha: JsonUtility doesn’t support Dictionary or float3. Use float[] arrays or Newtonsoft.Json.

MethodUse WhenNotes
JsonUtilitySimple data, no DictionaryFast, no package needed
Newtonsoft.JsonComplex types, polymorphismMore flexible
BinaryWriterPerformance-criticalManual field writing
BinaryFormatterNeverDeprecated, insecure

→ See references/save-patterns.md for full SaveManager, binary, versioning, auto-save, and encryption code.

  • Versioning: Include int version in SaveData, migrate in LoadWithMigration()
  • Auto-save: InvokeRepeating + OnApplicationPause + OnApplicationQuit
  • Encryption: XOR for obfuscation; System.Security.Cryptography.Aes for real security
  • Atomic write: Write to temp file, then rename to avoid corruption
  1. WebGL: No filesystem — use PlayerPrefs or IndexedDB via JS interop
  2. Threading: File I/O on main thread causes hitches — use async/await
  3. iOS: iCloud backup includes persistentDataPath by default
  4. Save corruption: Always write temp → rename (atomic operation)
  • unity-addressables — Loading saved asset references
  • unity-mobile — Platform-specific save paths
  • unity-scene-management — Save/load scene state
  • dots-rpg — DOTS game state (use dots-implementer agent)
FileContents
references/save-patterns.mdFull code: JSON, binary, versioning, auto-save, encryption, gotchas