Search Unity

Scriptable objects data dont save in asset folder

Discussion in 'Scripting' started by Mak992, Jul 9, 2021.

  1. Mak992

    Mak992

    Joined:
    Oct 2, 2018
    Posts:
    9
    I have made a scriptable object BlockData1 i then make the different block data with the creation tab. When i reset my game, the BlockData i made resets or losing it's script. The point is that it is not saving the data that i put in it. How do i fix this
     

    Attached Files:

  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Scriptable objects are only saved when you're in edit mode and you don't instantiate them, any other time (at least as far as my experiences go) it's not permanent. I personally used playerprefs to store the most important portions to save and used that.
     
  3. Mak992

    Mak992

    Joined:
    Oct 2, 2018
    Posts:
    9
    Indeed i only create my blockdata in edit mode from the create menu and my custom tab gained from CreateAssetMenu.
    The problem is, when i reset the game my blockdata. as seen in the picture "What it looks like after resetting my game". the blockdata object copper says it is missing a script or the values was not saved. How do i make sure that unity saves these values even though i restart my game?
    Before restarting the same instance of the copper would have fields as block name and sell price and what not.

    My initial idea was to have a scriptableobject class blockData and from that create Gold , Copper , .... and then the information would be saved in those like showen on the "What it looks like after resetting my game"
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    In the editor, all changes to ScriptableObjects during edit and play mode persist. If you need to modify the data but want that data to be reset when you exit play mode, create a copy of the ScriptableObject in Awake/Start and use that instead.
     
  5. Mak992

    Mak992

    Joined:
    Oct 2, 2018
    Posts:
    9
    My problem is, that my data do not persist when i restart my computer or closes and opens the project
     
  6. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    So if you make a brand new Blockdata1 ScriptableObject via the Create menu, set the sell price in the inspector, then close and re-open Unity... it's just gone?
     
  7. Mak992

    Mak992

    Joined:
    Oct 2, 2018
    Posts:
    9
    Yeah exactly and i have used ScriptableObjects before where it did not happen. which makes the whole situation very weird. It looks like it is missing the script or something like that. Ref to the picture "What it looks like after resetting my game"
     
  8. DarkSealer

    DarkSealer

    Joined:
    Nov 24, 2015
    Posts:
    10
    Did you solve that? I have the same problem and it seems that once I changed a property of my scriptableobject once it can't be changed back which is really weird. And if I stop the game, the change persist but I can't change it back in play mode.
     
  9. pokelocos

    pokelocos

    Joined:
    Nov 9, 2015
    Posts:
    54
    Not all data types can be serialized, I don't have the correct answer but the use of dictionary or texture may be what is causing the conflict, try changing the dictionary for another type of structure.