> For the complete documentation index, see [llms.txt](https://docs.meshmap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.meshmap.com/unity-sdk/building-blocks/save-system.md).

# Save System

The **Save System** allows persistent saving and loading of component state across scenes.

## Components

### [ISaveable](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/SaveSystem/ISaveable.cs)

* Interface to make a behaviour's state persistent.
* Must define a `SaveId` (string) and state serialization logic.

### [SaveableMonoBehaviour](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/SaveSystem/SaveableMonoBehaviour.cs)

* Base `MonoBehaviour` implementing `ISaveable` for convenience.
* Override save/load methods to store component-specific data.

### [SaveManager](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/SaveSystem/SaveManager.cs)

* 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.

### [SaveManagerUI](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/SaveSystem/SaveManagerUI.cs)

* Optional UI component to expose save/load/reset actions to the player.

### [SavePrefs](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/SaveSystem/SavePrefs.cs)

* Static helper for storing save data in `PlayerPrefs`.
* Includes `ResetAll()` to clear all stored state.

## Example Workflow

1. Add `SaveManager` to your scene.
2. Implement `ISaveable` on components whose state should persist.
   1. Tip: inherit from `SaveableMonoBehaviour` for clean integration with Unity callbacks.
3. Auto-assign unique `SaveId`s to each object using the `SaveManager` Inspector component.
4. Call `SavePrefs` methods or use `SaveManager` to save/load.
5. Add an optional button to your in-app UI to call `SaveManager.ResetAllSaveables()`.

## Example Code

```csharp
// 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);
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.meshmap.com/unity-sdk/building-blocks/save-system.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
