Save System is a simple save system for Unity. It allows you to save and load scene objects and their components.
- Saving and Loading
- Save Meta Data
- Using the Savable Component
- Prefab Registry
- Create your own Savable Component
- Data Types
- Reading Values Safely
- Supported Types
- Install via git URL
- License
You can save and load the current scene by using the SaveLoadManager class.
using Kekser.SaveSystem;
// ...
SaveLoadManager.Save(path);
SaveLoadManager.Load(path);
// load into a freshly loaded scene, even if it is already the active one
SaveLoadManager.Load(path, reloadScene: true);A save is written to a temporary file first and then moved into place, so a crash while saving never
leaves a broken file behind. SaveLoadManager.IsBusy is true while a save or load runs.
You can store meta data with a save (a version, what a save slot shows, ...) and read it back without loading the save.
DataObject meta = new DataObject();
meta.SetValue("Version", 2);
meta.SetValue("Level", "Harbour");
SaveLoadManager.Save(path, meta);
DataObject saved = SaveLoadManager.LoadMeta(path); // null if there is none
int version = saved.GetValue("Version", 0);You can save and load a scene object by adding the Savable component to it.
You can use it on any scene object, but it is recommended to use it on Prefabs.
This package contains a SavableTransform and a SavableRigidbody component.
You can use them to save and load the transform and the rigidbody of a scene object.
Savable fields and methods are also found on base classes, so a component inherits what its base class saves.
Children of a Savable are only written when they (or their children) have something to save.
Scene objects get a random guid. If your scenes are generated (and so recreated with new guids), give them a fixed one, e.g. derived from the object's name, so older saves still find them:
savable.SetGuid(myStableGuid); // in the editor, mark the component dirty afterwardsTo be able to save and load prefabs, you have to register them in the PrefabRegistry.
You can create and update the prefab registry by clicking on Tools/Save System/Update Prefabs.
This is a manual process, and needs to be done every time you add a new prefab to your project.
You can create your own savable component by using the Savable, Save or Load attribute.\
using Kekser.SaveSystem.Attributes;
[Savable]
private int _score = 100;using Kekser.SaveSystem.Attributes;
using Kekser.SaveSystem.Data;
private int _score = 100;
[Save]
private void Save(DataObject data)
{
data.Add("Score", new DataElement(_score));
}
[Load]
private void Load(DataObject data)
{
_score = data.Get<DataElement>("Score").ToObject<int>();
}These attributes are also usable on static fields and methods.
The DataObject class is a dictionary that contains other DataObject, DataArray and DataElement objects.
The DataArray class is a list that contains other DataObject, DataArray and DataElement objects.
The DataElement class is a wrapper for any supported types.
Saves outlive code changes. SetValue, GetValue and TryGetValue on a DataObject make reading tolerant of
missing keys (e.g. a value added in a later version):
[Save]
private void Save(DataObject data)
{
data.SetValue("Score", _score);
}
[Load]
private void Load(DataObject data)
{
_score = data.GetValue("Score", 100); // 100 if the save has no "Score"
}A saved field that no longer exists, a component type that was renamed and a failing load method are logged and skipped; the rest of the save still loads.
byte[]intfloatboolstringVector2Vector3Vector4QuaternionColorTypeGuidIListIDictionaryArrayEnumClassStructGameObject
You can add this package to your project by adding this git URL to the package manager:
https://github.com/DerKekser/unity-save-system.git?path=Assets/Kekser/SaveSystem
This library is under the MIT License.


