How to Create a Save System in Unity Using JSON
Wed Feb 25 2026
Why You Need a Save System in Unity
If your game has:
- Player progress
- Levels
- Inventory
- Health or stats
- Unlockable content
You need a save system.
Without saving, players lose progress every time they close the game. That is frustrating and game-breaking.
The good news is: building a save system in Unity using JSON is simple and beginner-friendly.
Why Use JSON for Saving Data?
JSON is:
- Human-readable
- Lightweight
- Easy to debug
- Built into Unity with
JsonUtility
It is perfect for storing structured data like player stats and game progress.
Example of JSON data:
{
"playerName": "Hero01",
"level": 5,
"health": 80,
"coins": 150
}
Step 1: Create a Data Class
First, create a C# class that represents the data you want to save.
[System.Serializable]
public class PlayerData
{
public string playerName;
public int level;
public int health;
public int coins;
}
Important: The class must be marked as [System.Serializable] for Unity’s JsonUtility to work.
This class defines what will be saved.
Step 2: Create a Save Manager Script
Now create a script called SaveManager.cs.
using UnityEngine;
using System.IO;
public class SaveManager : MonoBehaviour
{
private string filePath;
private void Awake()
{
filePath = Application.persistentDataPath + "/playerdata.json";
}
public void SaveGame(PlayerData data)
{
string json = JsonUtility.ToJson(data, true);
File.WriteAllText(filePath, json);
Debug.Log("Game Saved to: " + filePath);
}
public PlayerData LoadGame()
{
if (File.Exists(filePath))
{
string json = File.ReadAllText(filePath);
PlayerData data = JsonUtility.FromJson<PlayerData>(json);
Debug.Log("Game Loaded");
return data;
}
else
{
Debug.Log("No Save File Found");
return null;
}
}
}
This script:
- Converts data to JSON
- Writes it to a file
- Reads it back when needed
Step 3: Connect It to Your Player
Now let’s use it inside your Player script.
public class Player : MonoBehaviour
{
public string playerName;
public int level;
public int health;
public int coins;
public SaveManager saveManager;
public void Save()
{
PlayerData data = new PlayerData();
data.playerName = playerName;
data.level = level;
data.health = health;
data.coins = coins;
saveManager.SaveGame(data);
}
public void Load()
{
PlayerData data = saveManager.LoadGame();
if (data != null)
{
playerName = data.playerName;
level = data.level;
health = data.health;
coins = data.coins;
}
}
}
Now your player can:
-
Save progress
-
Load previous data
You can connect these methods to UI buttons.
Where Does Unity Save the File?
Unity uses:
Application.persistentDataPath
This ensures:
-
Windows saves correctly
-
Android saves correctly
-
iOS saves correctly
-
Console builds work properly
Never hardcode file paths.
Improving the Save System
Once the basic system works, you can improve it.
Add Encryption
To prevent cheating, you can:
-
Encode the JSON
-
Encrypt the file
-
Use Base64 encoding
Add Auto Save
Call Save():
-
After level completion
-
After checkpoints
-
On application quit
Save Multiple Files
You can create:
-
Player profile saves
-
Settings saves
-
Inventory saves
-
World state saves
Just change file names.
Common Beginner Mistakes
Forgetting [Serializable]
Without it, Unity cannot convert your class to JSON.
Not Checking File Exists
Always verify before loading.
Overwriting Data Accidentally
Be careful when auto-saving.
Saving Too Frequently
Writing to disk constantly can affect performance.
When to Use JSON vs PlayerPrefs
Use JSON when:
-
You have structured data
-
You need complex objects
-
You want readable save files
Use PlayerPrefs when:
-
Saving small values
-
Storing simple settings
-
Managing volume, resolution, toggles
JSON is better for real game progress.
Scaling This System
As your game grows, you may want:
-
ScriptableObject integration
-
Cloud saves
-
Versioned save files
-
Save slot management
-
Binary serialization for performance
But JSON is the perfect starting point.
Apptastic Insight
A save system is not just a technical feature.
It protects the player’s time.
Even beginner games feel professional when:
-
Progress is preserved
-
Data loads correctly
-
Players trust the system
Start simple.
Build clean.
And let your players continue their journey exactly where they left off.
Wed Feb 25 2026
