Save & Load System
The EntityManagerObject provides a flexible and lightweight save/load system based on JSON serialization. It is designed to handle large numbers of Entities and custom gameplay data in a simple and extensible way.
This page explains how to implement:
- Multiple save slots
- Custom game save data
- Entity Manager API usage
- Persistent save slot selection
- Dirty flag optimization
Basic Save Architecture
The save system is split into two parts:
-
Entity Manager Data Handled automatically by the system, including:
- Entity Attributes
- Entity CustomData
- Inventory Data/Character Customization Data/etc
-
Extra Game Data (User-defined) Used for anything outside entity data, such as:
- Player progression
- Quest state
- World flags
- Settings
- Save slot metadata You define this using a serializable class.
Creating Custom Save Data
To store additional game-specific information, create a Serializable class:
[System.Serializable]
public class GameSaveData
{
public int playerLevel;
public float playTime;
public string currentScene;
public Vector3 playerPosition;
}
This data will be stored alongside Entity data as JSON.
Saving Data (Multiple Save Slots)
You can support multiple save slots by using a save index:
public void Save(GameSaveData _data, int _saveIndex)
{
string _extraString = JsonUtility.ToJson(_data);
GameManager.EntityManagerData.Save(
GameManager.GetFullSavePath("UserSave" + _saveIndex.ToString() + ".sav"),
_extraString
);
}
What happens here:
GameSaveData→ converted toJSON- EntityManagerObject data is saved automatically
- Both are stored in the same save file
Loading Data
To load a save slot:
public void Load(int _saveIndex)
{
string _extraString = GameManager.EntityManagerData.Load(
GameManager.GetFullSavePath("UserSave" + _saveIndex.ToString() + ".sav")
);
GameSaveData _data =
(GameSaveData)JsonUtility.FromJson(_extraString, typeof(GameSaveData));
// Apply loaded data here
}
After loading:
- EntityManagerObject system restores all Entities automatically
- You restore your custom game state manually
Managing Save Slots
A common approach is to store the last selected save slot:
Example workflow:
- Player selects Save Slot (0, 1, 2...)
- Store selected index in a separate config file or PlayerPrefs
- On game start:
- Load last used save index
- Call Load(saveIndex)
This allows seamless Continue Game functionality.
EntityManagerObject API Reference
Saving & Loading
public void ToJson(string _extraInfo)
Converts all entities and extra info into a JSON string.
public string FromJson(string _json)
Loads entity data from JSON and returns stored extra info.
Full Save System
public void Save(string _path, string _extraInfo)
Saves all entities + extra data to a file.
public string Load(string _path)
Loads all entities + extra data from a file.
Single Entity Operations
public string SingleEntityToJson(string _uid)
Returns JSON for a single entity.
public void SaveSingleEntity(string _uid, string _path)
Saves a single entity to a file.
public void LoadSingleEntity(string _uid, string _path)
Loads a single entity from a file.
Performance Optimization (Dirty Flag)
To improve performance in large projects, the Entity class includes a dirty flag:
public bool isDirty;
How it works:
isDirty = true→ Entity has been modified- Your save logic can ignore unchanged Entities
- Improves performance for large worlds
This reduces unnecessary serialization work in large projects.