Save Systems: What Survives a Session vs a Restart
Snapshot
~80 sec
Decide what must survive a restart before picking a save format for it. A run-scoped value (current session score) can live in memory; a session-scoped value (an energy gate's timer, an invented currency balance) needs an actual save file that outlives the process.
You will learn
- Separate state that only needs to survive a scene change from state that must survive a full restart.
- Compare PlayerPrefs against a structured save file for different kinds of data.
- Explain why a session gate (like an energy timer) has stricter save requirements than cosmetic settings.
Target outcome
You can look at one invented value and say whether it needs no save, PlayerPrefs, or a structured save file.
Visual walkthrough
Visual walkthrough
~6 min
Three different lifetimes
Run-scoped
Lives only for the current play session - lost on quit, and that is fine (e.g. current combo count).
Session-scoped, persistent
Must survive quitting the app entirely - an energy timer, a currency balance.
Save file
Structured data written to disk (or cloud) so persistent state survives a full restart.
PlayerPrefs versus a structured save file
Approach Data shape Corruption risk Good fit for PlayerPrefsSimple key-value storage built into Unity. Flat key-value pairs only - no nested structure. Fine for small, low-stakes values; not built for large or critical state. A volume setting, a "has seen tutorial" flag. Structured save file (e.g. JSON)A serialized object written to a save file you control. Nested, versionable structures - inventory, currency, timers together. You control write timing and can add backups or checksums. An energy session gate's timer, currency balances, unlocked progression. Sort three values by save need
Sort these into "no save needed," "PlayerPrefs is fine," or "needs a structured save file": (1) current combo streak this run, (2) music volume, (3) an invented soft-currency balance with a session energy gate.
Expected reasoning
Combo streak needs no save - it is run-scoped and resetting on quit is correct. Music volume fits PlayerPrefs - simple, low-stakes, flat. The currency balance and energy gate need a structured save file, since they must survive a restart, relate to each other, and matter enough to justify more careful handling.
Go deeper
- Unity Scripting API: PlayerPrefsReference for simple key-value persistence and its limits.