Search Unity

Scriptable objects for store data.

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

  1. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    375
    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,913
    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. 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.
     
    Baloouis, WILEz1975, inemeth and 4 others like this.
  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:
    375
    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:
    133
    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