Search Unity

ScriptableObject data not staying stored when edited from Editor code.

Discussion in 'Scripting' started by S_P, Aug 18, 2019.

  1. S_P

    S_P

    Joined:
    Sep 20, 2014
    Posts:
    55
    I'm NOT trying to store data in ScriptableObject in runtime/executable/build.

    I'm trying in edit mode but from editor code. It show data as they are being edited. But changes don't stay. Version controller doesn't detect any changes in the scriptableobjects. Also after restarting Unity all changes are gone. But that was only supposed to happen runtime. Manual changes like editing with keyboard stay BTW.

    What am I missing? Should I go for other solution like json, xml, bin, text?
     
  2. S_P

    S_P

    Joined:
    Sep 20, 2014
    Posts:
    55
    In case anyone face the same problem, here is the solution. You need to let the editor know that some assets are being changed and save those assets.

    Code (CSharp):
    1. EditorUtility.SetDirty(object);
    2. AssetDatabase.SaveAssets();