---
description: 5_ScriptableSave
---

# Useful Methods

If you scroll down in this script, you'll see the implementation of the Scriptable Save Example SO. This is also where you can customize it for your game. In my case, I added a few practical public getters and various public methods like SetLevel(), AddRandomItem(), ClearItems(), and more.

It is recommended to only allow this class to modify the \_saveData directly and make all other classes use the public methods to affect the save. This way, you ensure that all modifications of the save are centralized in this class, and you can control it. Note that after each modification, I manually call Save().

```csharp
public void AddRandomItem() => AddItem(new Item("RandomItem_" + Items.Count));

public void AddItem(Item item)
{
    _saveData.Items.Add(item);
    Save();
}

public Item GetItemById(string id)
{
    return _saveData.Items.Find(item => item.Id == id);
}

public void ClearItems()
{
    _saveData.Items.Clear();
    Save();
}

public void IncrementLevel(int value)
{
    _saveData.Level += value;
    Save();
}

public void SetLevel(int value)
{
    _saveData.Level = value;
    Save();
}
```

Depending on your game or save mode, you might not want to trigger a save after each modification.

Let's try now to use these methods. If you check the Items buttons in the hierarchy, you can see that each button directly references the scriptable save SO and calls a public method.

![](https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2FEt06oVBmyC8b3Ptlmo06%2F4.png?alt=media)

![](https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2FcIKhJBfUdlsrABYbzngD%2F5.png?alt=media)

Play the game and start adding items, then clearing them. You will see that the changes are reflected in the save.

Scriptable Save SO also comes with built-in public methods:

* Save()
* Load()
* PrintToConsole()
* Delete()
* Open File Location()

These are very useful and you can access them freely from code or from the inspector (like the buttons on the Save Reader). You can also expose them in a custom inspector to quickly access them for debug.

![](https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2FST2SQjXtZGm0B64YqO9y%2F6.png?alt=media) ![](https://1391552916-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqhD9b0UbiZjyC9B8azX%2Fuploads%2FCGxzIqcZK28GORtnnuqg%2F7.png?alt=media)
