Page 1 of 1

Save Scriptable Object

Posted: Sat Mar 21, 2020 5:22 pm
by Johnny Star
Hello, I'm trying to find a tutorial specifically targeted towards Scriptable Objects, but can't seem to find any.

I have an inventory system that uses a list to store items into it.
Image

The items are Scriptable Objects too. So what I had in mind was:
1) Get the list of items and references, save them normally where everything else is saved to by default (at the persistent data path).
2) Empty the list of the Scriptable Object inventory on application quit.
3) On load, get the inventory system SO and repopulate it with the list of items that were saved.

The question is: Is this the way to do it? Or is there another way ES3 does the saving of Scriptable Objects?
I'm also new to this so please let me know if there's anything that I should look out/be aware of.

Thank you!

Re: Save Scriptable Object

Posted: Sun Mar 22, 2020 8:31 am
by Joel
Hi there,

ScriptableObjects are generally saved and loaded like any other data, though be aware that they are saved by reference when you save a script which has a ScriptableObject field.

So in your case I would generally save all of the Items in a List or array, and then save the BagInventory. Then when you come to load, load the List of Items first, and then load the BagInventory.

All the best,
Joel