Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Scriptable objects for store data.

Discussion in 'General Discussion' started by WILEz1975, May 27, 2020.

  1. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    368
    I have doubts about scriptableObjects.
    I'm an old Unity user (since Unity 3) and some (relatively new) features I've never used.

    The most talked about feature is saving persistent data to an object. As an ever persistent script.
    I have read several tutorials on the subject but there is one thing I did not understand.

    How can you use this functionality if the original object variables are changed?
    If I had multiple saves (like the classic saving slots) how can a scriptableObject work for this function if the object being modified is the original one?

    If for example I have an inventory that uses a scriptable object to be persistent, what if I want to open a save other than the last one?
    Or if you want to start a new game? If the original file has been modified, would I have the data of the last state of the scriptable object?
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,843
    It's better for saving editor scripts, such as the post processing profiles. If you are trying to use it like a save game, then there is only one scriptable object. You can use ScriptableObject.CreateInstance, but this is just the same as using a regular C# class instance.
     
    WILEz1975 and AdrianRio like this.
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,792
    ScriptableObjects aren't persistent. Only in the Editor.
    When you make a build, run your game, change something in the ScriptableObject, exit the game and restart it, it won't retain the change.
    You still need a proper save system to achieve persistence.

    SOs are persistent between scenes though given their asset nature.
     
  4. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    See scriptable objects as data blueprints that you then create instances of at runtime. Much like prefabs but without the need of having a transform in the scene
     
  5. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    My scriptable objects are always saying it cant be loaded
     
  6. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    368
    Thanks to all of the answers! I go back to my old serialization system. ;)
     
    inemeth likes this.
  7. tchris

    tchris

    Joined:
    Oct 10, 2012
    Posts:
    128
    This really gave me some ideas on how to use Scriptable Objects properly. Especially when he talks about the Tanks demo at about 36:00