Useful Methods
5_ScriptableSave
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().
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.
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.
Last updated