How can I make my data in Odin Editor Windows persistent?

One way of accessing and storing persistent data when using OdinEditorsWindow's is by using Unity's EditorPrefs, together with Odin's ability to show properties. Here is how something like that would look.

public class SomeWindow : OdinEditorWindow
{
    [MenuItem("Test/Test")]
    private static void OpenWindow()
    {
        GetWindow<SomeWindow>().Show();
    }

    [ShowInInspector]
    public int MyPersistentEditorField
    {
        get { return EditorPrefs.GetInt("MyPersistentEditorField"); }
        set { EditorPrefs.SetInt("MyPersistentEditorField", value); }
    }
}

However EditorPrefs are not stored together with your Unity project, so if you want the data to be shared by everyone with the project, you'll have to look for alternative methods.

The way we do it in Odin, and in our internal development systems as well, is by storing all our persistent data in ScriptableObjects. We then pimp it up using Odin attributes to make a nice inspector/editor. And instead of accessing the editor by locating the ScriptableObject in the project view and inspecting it, we make a custom editor window, that simply draws the ScriptableObject and nothing more. That way it's more easily accessible for everyone.

To help out with this, we have created a small abstract class, GlobalConfig, that inherits from ScriptableObject. It's not needed at all, it's just a small utility you can use if you want a convenient way to make a singleton-like ScriptableObject. It automatically creates the file if it doesn't exist, etc...

The ScriptableObject Singleton using our GlobalConfig
// You can also specify a location for your persistent data to be inside an Editor folder in order to prevent the scriptable object from ever being included in your game.
[GlobalConfig("Resources/MyConfigFiles/")]
public class MyPersistentDataSingleton : GlobalConfig<MyGlobalConfig>
{
    public int SomePersistentField;
}

Note that GlobalConfig is serialized by Unity, not Odin. However, you can easily add Odin serialization support to your class yourself with only a few lines of code. Check out the Serialize Anything section from our manual, and look for ISerializationCallbackReceiver.

Creating the Editor Window
public class MyEditorWindow : EditorWindow
{
     private Vector2 scrollPos;
     private Editor editor;
 
     [MenuItem("Test/Test")]
     private static void OpenWindow()
     {
          GetWindow<MyEditorWindow>().Show();
     }
 
     private void OnEnable()
     {
          this.editor = Editor.CreateEditor(MyPersistentDataSingleton.Instance);
     }
 
     private void OnGUI()
     {
          this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos);
          GUIHelper.PushHierarchyMode(false);
          this.editor.OnInspectorGUI();
          GUIHelper.PopHierarchyMode();
          EditorGUILayout.EndScrollView();
 
          this.RepaintIfRequested();
     }
 
     private void OnDestroy()
     {
          DestroyImmediate(this.editor);
     }
}

Here is an image of this concept in action, when it's taken a few steps further.

Can I use Odin for its editors only, without using the serialization? Can I use Odin for its editors only, without using the serialization?
Can I use Odin to make inspectors for my own asset store plugins? Can I use Odin to make inspectors for my own asset store plugins?
Can I use Odin Inspector to create custom editor windows? Can I use Odin Inspector to create custom editor windows?
Does the serialization support Windows Store and UWP? Does the serialization support Windows Store and UWP?
How do I contact Sirenix to report bugs, suggest features, or in general? How do I contact Sirenix to report bugs, suggest features, or in general?
Does Odin support serialization of Unity object references? Does Odin support serialization of Unity object references?
Does Odin support interfaces? Does Odin support interfaces?
How can I add an image to the inspector? How can I add an image to the inspector?
Why isn’t Odin drawing the inspector for my script? Why isn’t Odin drawing the inspector for my script?
Why is Odin not serializing or showing my field or property? Why is Odin not serializing or showing my field or property?
How will Odin handle existing editors? How will Odin handle existing editors?
How can I make a list show one item per page? How can I make a list show one item per page?
Does Odin support cross scene references? Does Odin support cross scene references?
Can I disable or hide an inspector property in play mode, or vice versa? Can I disable or hide an inspector property in play mode, or vice versa?
Which platforms are supported by Odin? Which platforms are supported by Odin?
How easy is Odin to uninstall? How easy is Odin to uninstall?
How will Odin affect performance in the inspector? How will Odin affect performance in the inspector?
Unity crashed, could this have something to do with Odin? Unity crashed, could this have something to do with Odin?
How can I show static fields and properties in the inspector? How can I show static fields and properties in the inspector?
Can I use Odin's serialization without inheriting from SerializedMonoBehaviour etc.? Can I use Odin's serialization without inheriting from SerializedMonoBehaviour etc.?
How fast is Odin's Serialization system? How fast is Odin's Serialization system?
How stable/reliable is Odin's serialization system? Can I safely use it in my project? How stable/reliable is Odin's serialization system? Can I safely use it in my project?
Is it possible to customize how the dictionary drawer draw its key-type using attributes? Is it possible to customize how the dictionary drawer draw its key-type using attributes?
How can I make an attribute that lets you drag elements unto a member to set its value? How can I make an attribute that lets you drag elements unto a member to set its value?
Why are my values disappearing when I hit play? Why are my values disappearing when I hit play?
Can I write my own custom editor code using Odin? Can I write my own custom editor code using Odin?