Save datausing Scriptable object

(Question summary: why Scriptable object data saves between playmode sessions but doesn’t save is i close unity project and open it again, and what is a good way to make data remain permanently?)
Hello! im making a farming game and using scriptable objects to handle all the data. And today i notised an issue.
Data is stored properly between play mode sessions, but if i close unity and open it again, all data returns to default values, assigned in inspector. Here is an example:

  1. i started playmode: (building are on their default place)
  2. i moved a building in playmode: (and than exit playmode)
  3. i entered playmode again: (building remains where i set it)
  4. but than i closed unity project, opened it again, entered playmode, and this happened:
    (red building returned to default position)

I built my project and found out that there is the same issue: if i close game all the data returns to default values.

I use Scriptable object that stores vector to value to save position of the building, here it is:

No scriptable objects cannot be used as save data in this manner. Particularly in a build a scriptable object will revert to its initial serialised/default values when it is no longer referenced by anything in a scene.

You can, of course, during a play sessions, use scriptable objects to hold onto this data in an easily reference-able manner, but you will still need to write these data to disk in save files.

That said serialised values in scriptable objects should maintain themselves between editor sessions. In your case your values may not be getting properly serialised, or Unity isn’t aware the values have changed (ergo, hasn’t dirtied the object) and that it needs to write the data to disk.

Long story short, there is no escaping the need to write out save data to disk, such as with JSON.

1 Like

thanks!