Editor data serialization

I have a custom selection class, which is now static (mainly because i don’t know who should house an instance of this object).
This object holds a list of selected objects (not UnityEngine objects, just my custom ones) and i’d like to keep the selection when i enter playmode by serializing and then deserializing the selection. But i don’t know where would be the correct place to hook the serializedObject i’d create for this purpose.

My only idea right now is to use one EditorWindow which would serialize data inside itself.

If you want to store a ScriptableObject, this page may help. It’s the same concept as a prefab: it’s stored on disk and when you click on it (or reference it from an object of the scene), UnityEditor will instantiate/deserialize it and display an inspector. The main difference between ScriptableObjects and prefabs is that ScriptableObjects can’t have Updates etc… and must be created by script instead of drag & drop in the project’s window. In my projects, I sometimes use a prefab/gameobject exactly as I would use a ScriptableObject, I just disable the GO in the inspector so it’s instantiated disabled; I didn’t see any CPU/MEM cost difference with a scriptableobject.

Now, you can also have a custom inspector on a ScriptableObject, it’s sometimes more convenient than an EditorWindow.

If you need an EditorWindow, you’ll have to instantiate/deserialize the prefab or ScriptableObject yourself before modifying it. Use AssetDatabase.LoadAssetAtPath to get an instance of the prefab/ScriptableObject and modify it. Use also EditorUtility.SetDirty and AssetDatabase.SaveAssets to save all modifications on all objects.