ScriptableObject data does NOT persist if i do not set values in the inspector

I have an editor window , the content of the editor window is generated from data read from a scriptable object.

okay so I want to set a bool by clicking a button in my editor window .

here is a perfect example of where i am at .

// this is your class which inherits from ScriptableObject
Create an instance of the sctiptableObject using AssetDatabase
using System;
using System.Collections;
using UnityEditor;
using UnityEngine;

[System.Serializable]
public class CompProject : ScriptableObject
{
 public bool testbool;

}

**//---------------------------------------Script2--------------------**

  using System;
 using System.Collections;
 using UnityEditor;
 using UnityEngine;

[System.Serializable]
    public class compInterface:EditorWindow
    {
  [MenuItem("Window/Comp")]
        static void init()
        {
            EditorWindow.GetWindow(typeof(compInterface));
        }

public CompProject compproj;

void OnGUI()
{

    if (!compproj)
    {
        if (Selection.activeObject.GetType() == typeof(CompProject)) compproj = Selection.activeObject as CompProject;
    }

    if (GUI.Button(new Rect(500, 200, 100, 40), " ")) compproj.testbool = !compproj.testbool;

}

}

The button will set the bool in the scriptableObject and i can also see that it is set in the editiow window.

Whenever I close and re-open unity , the value is set back to what it was before . however the value remains if i just set it from the inspector

what is the difference between just setting a bool with a button in the editor window and just setting it directly in the inspetor.

I swear it in no more complex than the code i posted. The data should just serialize right ?? i make sure to click ‘save project’ right after

I have no idea of what to do.

Putting things back to how they were before runtime started is not unique to SObj. You can see that (expected) behaviour by ticking a bool checkmark in the Editor while the game is running, once you stop the game it goes back.

Consider UnityEditor.EditorUtility.SetDirty(compProj); after making any changes in code to flag those changes for saving.