Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Scriptable objects for store data.

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

  1. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    332
    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,552
    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.
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    5,457
    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:
    646
    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,834
    My scriptable objects are always saying it cant be loaded
     
  6. WILEz1975

    WILEz1975

    Joined:
    Mar 23, 2013
    Posts:
    332
    Thanks to all of the answers! I go back to my old serialization system. ;)
     
unityunity