A free, modular, scriptable object based local save system for Unity.
✔️ Save editor window for editing the save data in edit mode
✔️ Save captures to load save states in the editor
✔️ Modular save setup
✔️ Save Encryption available
✔️ WebGL support!
✔️ Easily extendable with custom save storage locations & encryption options
✔️ Custom savable dictionary type included.
The asset is developed and maintained in 2020.3.x and make use of available .Net updates in the version. Older versions of Unity are not supported for this asset. The asset has been tested pre-release in its development version: 2020.3.0f1.
Any 2.x changes will be based around the 2.x branch in this repo.
Latest:
The most up-to-date version of the repo that is considered stable enough for public use.
https://github.com/CarterGames/SaveManager.git
Specific branch:
You can also pull any public branch with the following structure.
https://github.com/CarterGames/SaveManager.git#[BRANCH NAME HERE]
An example using the pre-release branch for 3.0.0 would be:
https://github.com/CarterGames/SaveManager.git#prerelease/3.0.0
Unity Package:
You can download the .unitypackage from each release of the repo to get a importable package of that version. You do sacrifice the ease of updating if you go this route. See the latest releases here
For more detailed instructions and API reference, please refer to the documentation.
A save object is basically a scriptable object that can store save values on it. When defined the save values on each object can be access in the editor and at runtime with ease. To make a save object you just need to make a class that implements the SaveObject class, or SlotSaveObject class if you want the data to be specifically used in save slots.
You can do this manually by making a class that inherits from the SaveObject clases or you can use the built-in SaveObject maker GUI. This can be found under:
Tools > Carter Games > Save Manager > Save Object Creator
The tool looks like this:
The save object creator window has a really simple set-up. You first enter the name of the class you want to make into the Save Object Name field on the GUI. Then if you have the Save Slots feature enabled you’ll be able to select between a global or slot save object. If not then it’ll be global by default behind the scenes and the option will be hidden from you.
Then all you need to do is press the Create Save Object button and choose where in the project’s assets folder the class should go. Once you confirm the location for the class it will be generated automatically for you.
A save value defines an entry in the game save. You define save values by using the generic save value class SaveValue as a field on in a SaveObject class. A valid save value MUST:
- Be placed inside of a class that inherits from SaveObject/SlotSaveObject, if not it will not function correctly.
- Be of a serializable type.
- Have a uniquely defined save key.
You have the option to also define a default value for the save value if you wish, but this is totally optional.
An example of a defined save value below:
[SerializeField] private SaveValue<int> playerHealth = new SaveValue<int>("playerHealth");
The save editor is the intended way for you to edit the save of your game. You can open the save editor window from the navigation menu’s Save Editor option.
Tools > Carter Games > Save Manager > Save Editor
The save editor is split into 4 tabs:
| Tab | Description |
|---|---|
| Global Data | Displays all the global save objects and their save values. |
| Save Slots | Displays all the save slots currently defines in the save and their save objects / save values. |
| Save Captures | A tool to help you store particular save files as a backup you can reload into your current save at any time. |
| Save Backups | Lets you view the current save backups and make save captures from any backup should you wish. |
The editor window looks like this:
See more details on how to use this window in the documentation.
All classes for the asset at runtime are under the following:
CarterGames.SaveManager.Runtime
CarterGames.Shared.SaveManager
(Optional, may be needed for some API)
CarterGames.Assets.SaveManager
Below is a short rundown of the most common API you'd be using.
public static bool IsBusy { get; }
Gets if the save manager is currently running a save or load operation.
public static void SaveGame()
Saves the game in its current state when called.
public static void LoadGame()
Loads the game from the stored save data when called.
public static T GetGlobalSaveObject<T>()
Gets the global save object of the defined type. For a safer call, please use the TryGetGlobalSaveObject() method instead.
public static T GetActiveSlotSaveObject<T>()
Gets a save object from the currently active slot of the defined save object type. For a safer call, please use the TryGetActiveSlotSaveObject() method instead.
public static T GetSlotSaveObject<T>(int slotId)
Gets a save object from the defined slot id of the defined save object type. For a safer call, please use the TryGetSlotSaveObject() method instead.
public static bool TryGetSaveValue<T>(string saveKey, out SaveValue<T> value, SaveCtx ctx = SaveCtx.Unassigned)
Tries to get a save value from anywhere in the save. Use SaveCtx to define the placement of the value in the save data set-up for a slightly faster call.
public T Value { get; set; }
The value stored in the save value. Use to access or edit the actual value stored in the save.
public static SaveSlot ActiveSlot { get; }
Gets the active save slot for use.
public static bool TryCreateSlot(out SaveSlot newSlot)
Tries to create a new save slot.
public static void LoadSlot(int slotId)
Loads the slot of the entered id.
public static void UnloadCurrentSlot()
Unloads the currently loaded slot when called.
public static void DeleteSlot(int slotId)
Deletes the slot of the entered id from the save system.
You can access a online of the documentation here: Online Documentation. An offline copy is provided with the package and asset if needed.
GNU V3
