Alternative to EditorWindow.OnDisable to run before compiling
Hi,
I have a script that creates threads, open .Net sockets, and runs in the Editor. The issue I have is that if any sockets are open, Unity hangs if I go and edit my code, at the point it compiles the code again it does not kill my threads and close my sockets (at least properly). In order to avoid Unity to hang I need to close any connection/thread before the code is recompiled.
So far the way I found to handle this is to close my sockets/threads in the OnDisable method of an EditorWindow, because it is called just before the code gets recompiled. I don't want to depend on having this EditorWindow opened in order to handle this.
Is there an alternative method that gets called just before the code gets recompiled? For example some static method, or anything in a MonoBehavior, or some delegate I could use in the EditorApplication class, etc.
Answer by Forest3 · Oct 08, 2017 at 06:01 PM
Ok, I found the solution here: http://answers.unity3d.com/questions/704066/callback-before-unity-reloads-editor-assemblies.html
The solution came 1 month after I asked this, in Unity 2017.1, I added this in the static constructor of my MonoBehavior:
AssemblyReloadEvents.beforeAssemblyReload += MyDisconnectMethod;
Answer by PiezPiedPy · Aug 21, 2019 at 02:09 PM
Thanks, your answer helped me get rid of the 'GarbageCollector disposing of ComputeBuffer allocated in...' warning by giving me a way to release the ComputeBuffers when recompiling. :D
Your answer
Follow this Question
Related Questions
How to change the text of EditorGUILayout.TextField 2 Answers
How can I display a scriptable object in a custom editor ? 1 Answer
How to create a curve editor? 0 Answers
Custom Editor Textarea cursor position 0 Answers
How to enter play mode on two separate Unity instances at the same time? 0 Answers