Save System
The Save System allows persistent saving and loading of component state across scenes.
Components
Interface to make a behaviour's state persistent.
Must define a
SaveId
(string) and state serialization logic.
Base
MonoBehaviour
implementingISaveable
for convenience.Override save/load methods to store component-specific data.
Central controller that manages all
ISaveable
components in the scene.Assigns unique IDs and coordinates save/load operations.
Editor inspector includes:
Assign SaveIds to All Saveables – Generates IDs for unassigned components.
Clear and Reassign – Resets IDs and clears stored preferences.
Optional UI component to expose save/load/reset actions to the player.
Static helper for storing save data in
PlayerPrefs
.Includes
ResetAll()
to clear all stored state.
Example Workflow
Add
SaveManager
to your scene.Implement
ISaveable
on components whose state should persist.Tip: inherit from
SaveableMonoBehaviour
for clean integration with Unity callbacks.
Auto-assign unique
SaveId
s to each object using theSaveManager
Inspector component.Call
SavePrefs
methods or useSaveManager
to save/load.Add an optional button to your in-app UI to call
SaveManager.ResetAllSaveables()
.
Example Code
// Example implmentation of the Save System for a collectable object, like a pickup item in a game.
public class Collectable : SaveableMonoBehaviour<CollectableState>
{
protected override CollectableState DefaultState => CollectableState.NotCollected;
protected override void Awake()
{
base.Awake();
// Deactive the collectable GameObject if it was already collected during a previous session
if (_currentState == CollectableStatus.Collected && DeactivateOnComplete)
{
gameObject.SetActive(false);
}
}
// Update the save status of the collectable GameObject so it is not active in the next session
public void GetCollected()
{
State = CollectableState.Collected;
SetSaveStatus();
if (DeactivateOnComplete)
{
gameObject.SetActive(false);
}
}
}
Last updated