- Home /
Save and (later) read scriptable objects
Hey everyone,
So in my game I currently have a system that creates a bunch of npc stat containers by using "create instance" of a new scriptable object, setting the variables inside to randomized values, and then adding this new SO to a list. This list can contain anywhere between 8 - 16 scriptable objects.
I have been trying to find some documentation about how I can save these new scriptable objects, as they are meant to be generated at runtime and will need to be called between different play sessions but I cant find any helpful information. If anyone knows anything about saving a list of scriptable objects, and later reading the list from file, I would really appreciate your help :)
Thanks for taking the time to read my questions either way !
Answer by Captain_Pineapple · Jan 31, 2019 at 01:03 PM
Hey there,
I'm not sure if i understand what your "scriptable object" is supposed to be but either way saving to JSON format mostly works out fine.
You can find a basic reference on how to do that HERE.
It basically transforms a Serializable object into a string based dictionary which can by saved to a file. Hope this helps!
Here is the ScriptReference of ScriptableObjects
https://docs.unity3d.com/ScriptReference/ScriptableObject.html
The JsonUtility
class is not able to serialize correctly nested ScriptableObjects.
Ah i see, I did not know that this existed. What is the use-case? why not create a pure class that is derived from nothing at all as a datacontainer?
Because scriptableobject can be stored as an asset file. Is automatically serialized and deserialized by Unity, moreover, serialization that supports the same inheritance as classes derived from $$anonymous$$onoehaviour.