All posts
UnityGuide

Unity Save System: PlayerPrefs vs JSON vs Binary (and How to Avoid Corrupted Saves)

November 5, 2026 DevLoot

Your game works, your players love it, and then someone loses 14 hours of progress because a save file got corrupted halfway through a write. Save systems are one of those things everybody builds in a hurry and regrets later. This guide walks through the three options Unity devs actually reach for (PlayerPrefs, JSON, binary), what breaks with each, and a setup that survives crashes, patches and curious players.

PlayStation and PlayStation 2 memory cards used to store game saves

Save data used to live on tiny cards. Photo by Pia via Wikimedia Commons (CC BY-SA 3.0).

PlayerPrefs: fine for settings, bad for saves

PlayerPrefs is the first thing everyone finds, and it is great at what it was built for: volume sliders, graphics quality, last selected language. It stores ints, floats and strings, nothing else. On Windows it lives in the registry, on macOS in a plist, and on mobile in platform preferences. That is the first problem: the data is scattered, hard to back up and trivial for players to edit.

The second problem is structure. The moment you want an inventory, quest states or a list of placed buildings, you start inventing string formats by hand. Don't. Use PlayerPrefs for options and keep real progress somewhere else.

PlayerPrefs is for what the player prefers. A save file is for what the player did.

JSON: the sane default for most indie games

For 90% of projects, JSON written into Application.persistentDataPath is the right call. It is human readable, so you can open a save and see why your quest flag is stuck. It diffs nicely, plays well with version control when you ship test saves, and you can migrate it between versions without much pain.

Unity gives you JsonUtility out of the box. It is fast and has zero setup, but it comes with limits that bite people constantly:

  • It cannot serialize Dictionary at all. You need two parallel lists or a wrapper.
  • It does not handle a top-level array, so you wrap everything in a root class.
  • It only touches public fields or fields marked [SerializeField], not properties.
  • Polymorphism is basically not supported. A list of Item will not remember it held a Sword.

If those hurt, install the official Newtonsoft package (com.unity.nuget.newtonsoft-json) from the Package Manager. It handles dictionaries, properties, type hints and custom converters. The cost is slightly more garbage and a few more milliseconds, which on a save that happens every few minutes is nothing.

[System.Serializable]
public class SaveData
{
    public int version = 2;
    public string sceneId;
    public float playTimeSeconds;
    public List<ItemStack> inventory = new();
}

string path = Path.Combine(Application.persistentDataPath, "slot1.json");
File.WriteAllText(path, JsonUtility.ToJson(data, true));

Binary: only when you have a reason

Binary saves are smaller and faster to parse, and they stop casual tampering. They also make debugging miserable. The big warning: do not use BinaryFormatter. Microsoft has marked it as insecure and unfit for untrusted data for years, and loading a tampered file can run code on the player's machine. If you truly need binary, use a purpose-built format like MessagePack or write your own with BinaryWriter and an explicit version header.

Honest take: if your save is under a few megabytes, binary buys you nothing but pain. Big open worlds with chunk data are the real use case. If you need to deter cheaters, encrypting a local save is a speed bump, not security. Anyone with a debugger wins. Spend that effort on server validation if your game has a leaderboard or economy.

The four rules that save you from corrupted files

1. Write atomically

Never write straight over the live file. Write to slot1.json.tmp, flush it, then replace the original (File.Replace or move over it). If the game crashes or the battery dies mid-write, the old save is still intact. This single habit prevents most "my save is gone" reports.

2. Keep a backup

Before replacing, keep the previous good file as slot1.bak. On load, if the main file fails to parse, fall back to the backup and tell the player. They will forgive losing five minutes, not five hours.

3. Version everything

Put an integer version at the top of every save. When you add a field in a patch, load old data, run a small migration step, and bump the number. Without a version you are guessing, and guessing breaks players' saves on update day.

4. Save data, not scene objects

Do not try to serialize GameObjects. Save plain data (IDs, positions, counts) and rebuild the scene from it. Static definitions like item stats belong in ScriptableObjects, and the save just stores the item ID. That keeps saves tiny and lets you rebalance items without invalidating anyone's progress.

Don't block the frame, and watch the platform

Write on a background thread or at least do it at safe moments (checkpoints, room transitions), not mid-combat. On consoles and WebGL, persistentDataPath behaves differently: WebGL uses IndexedDB and needs a sync call to actually commit, and console platforms have their own save APIs and size limits you must go through. Test on target hardware early, because "works in the editor" tells you nothing here. If you use cloud saves via Steam or a platform service, the same JSON file approach works well, you just upload the bytes.

So which one should you use?

Settings go in PlayerPrefs. Progress goes in JSON, via Newtonsoft if you need dictionaries or polymorphism, written atomically with a backup and a version number. Only reach for binary when profiling shows your save is actually too big or too slow. If you are building out systems like inventory or crafting, a pre-built save-friendly asset can save you a week, and you can browse game-ready Unity tools on DevLoot. But whatever you pick, build the save system early. Retrofitting it into a finished game is where the real pain lives.

Unity Save System: PlayerPrefs vs JSON vs Binary (and How to Avoid Corrupted Saves) · DevLoot