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 - MonoBehaviourimplementing- ISaveablefor convenience.
- Override save/load methods to store component-specific data. 
- Central controller that manages all - ISaveablecomponents 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 - SaveManagerto your scene.
- Implement - ISaveableon components whose state should persist.- Tip: inherit from - SaveableMonoBehaviourfor clean integration with Unity callbacks.
 
- Auto-assign unique - SaveIds to each object using the- SaveManagerInspector component.
- Call - SavePrefsmethods or use- SaveManagerto 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
