Is there a way to exclude a specific EditorWindow class from domain reload in Unity?
I donât believe so.
What specific problem are you trying to solve?
thank you . your reply.
I want to deep copy a class into a specific EditorWindow field and then copy it back into a specific class in the game code when restarting the editor.
Iâm not sure how that relates to a domain reload then. An editor window will persist its serialised data - so long as it remains open - through domain reloads. Just their OnEnable/OnDisable/OnDestroy calls will happen each domain reload.
Do you mean you want the data to persist between editor sessions? Thatâd just involve writing the data in a persistent way, such as into a scriptable object or even a regular text file, and reading/writing it at the correct times.
A scriptable singleton is a good way to persist data in an editor-only context: Unity - Scripting API: ScriptableSingleton<T0>
But Restart Editor ( Play Button ) . Reset ScriptableSingleton Field.
Okay I guess this is a language thing but âRestart Editorâ to me, means closing and reopening the editor. Youâre talking about entering/exiting play mode.
In any case, like I said, you need to actually write the data somewhere for it to persist (alongside ensuring itâs serializable). In the ScriptableSingleton example, you need to use the [FilePath]
attribute, and ensure you call Save() when it makes sense to ensure the data is written to disk, so it can be reloaded as necessary.
That said, if the data is serializable, it should persist between domain reloads in a scriptable singleton, or any scriptable object, as they maintain their state in memory throughout the lifetime of the editor/application session.
Thank you for your reply.
The class is not serializable. From ScriptableSingleton, it performs a DeepCopy on the dictionary in Source to a field within ScriptableSingleton. It has been confirmed that the data persists even when stopping the Editor. However, upon returning the Editor to Play mode, while the Count of the dictionary within ScriptableSingleton is maintained, its contents are deleted.
What does a âDeep Copyâ entail? Thereâs no standard meaning for that term. And when does the copy happen?
And by âStopping the editorâ, do you mean closing the editor, or exiting play mode?
Though the long and short is the data needs to be serialised/serializable in order to persist. Non-serialised values in scriptable objects will reset on domain reloads.
During a domain reload, all C# data gets lost. The editor will serialize supported classes before the domain reload and then de-serialize and re-create the objects afterwards. Anything thatâs not compatible with Unityâs serialization will get lost.
You have a few options:
- Change your data layout to be compatible with Unityâs serialization
- Convert your data to and from something Unity can serialize (e.g. using ISerializationCallbackReceiver you could convert to/from Json)
- Thereâs also SessionState to put things you donât want to tie to a Unity object
- Write your custom persistence, e.g. by saving to and loading from temporary files or using a native plugin