I have a class which inherits from AssetPostprocesso, as I do some Asset Post Processing, this class the attribute [InitializeOnLoad].
Upon entering Play-Mode in the editor this class is destroyed (witnessed by adding a debug log to the destructor). This class is not created again until the project is updated, (e.g. a new prefab is created by dragging in a gameobject to the project window). This causes some problems for me as have several callbacks that no longer work until the asset database is updated.
Is this intended behaviour?
If not I can provide a project which demonstrates the problem.
The delegate I subscribe to is: SceneView.onSceneGUIDelegate.
Is there another way of subscribing to this delegate, without having to physically have a object in the scene with a script on (i.e. no [ExecuteInEditMode]), which does not get destroyed upon entering Play-Mode?
You could create a class that inherits from ScriptableObject and set the property hideFlags to HideFlags.DontSave. You can then ScriptableObject.CreateInstance and it will persist through playmode. If you want to keep a reference to this class, or ensure there’s only one of it, then before wherever you call CreateInstance, you can do Resources.FindObjectsOfTypeAll and it will find your instance. Let me know if you need example code Short on time now. You can also just create an EditorWindow, probably easier.