Search Unity

Store Data to ScriptableObject

Discussion in 'Scripting' started by RoyalCoder, Jan 11, 2018.

  1. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Hi friends,

    I'm trying to save/load data on custom Scriptable Object, to reuse data in other sessions of game or scenes, can someone guide me with this? Thanks in advance!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Thanks @LeftyRighty ,

    I watched entire live training, but I didn't found my answer :( I will continue to research this topic!
     
  4. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    If you're talking about storing actual game / session save data at runtime, using ScriptableObjects isn't actually beneficial over using any other arbitrary object type, since you still have to manually store it on the physical drive. All of the ScriptableObject save/load functionality is a part of the UnityEditor assembly and not included in builds, so you'll need to save them the same way you save anything else- with a binary save system, JSON, XML, YAML (ironically), etc... You might as well use some other object type instead. Look into BinaryFormatter (for built-in data serialization), MessagePack, ZeroFormatter, JsonUtility, FullSerializer for some common serialization techniques for writing/loading objects to and from files.

    Alternatively, you can use PlayerPrefs for a built-in method to do much the same thing. The only problem with this is that people can wipe out all of it by using "Clear Cache" on Android/IOS. It's usable for any data that you don't necessarily mind losing from time to time, like the preferred resolution and default audio volumes, etc...
     
    BlissfulCarbon, Kekaku and Kritz01 like this.