I have an editor window with a button, that calls a lengthy routine, and I need to give some feedback to the user during execution, to let him know that the system has not hanged.
However there’s seemingly no method of doing this?
Can’t use coroutines since they’re a monobehavior thing, and can’t use yield since you can’t declare OnGUI as IEnumerator… so how are we supposed to do this, which should be trivial and ridiculously easy?
Any help appreciated. It’s two days wasted trying to get this to work.
Spawn a thread and sync up state from time to time to display in a custom progress bar somewhere in the UI.
I would recommend the first option as allowing the user to edit things while your editor script runs has a lot of potential for tragedy. There are only four parts of the standard editor which uses the second option - namely the asset server, the asset store, lightmap baking and navmesh baking.
What is the best place to block the main thread? Calling a several minutes long operation inside OnGUI seems to lead to some odd errors: “ArgumentException: You can only call GUI functions from inside OnGUI.” Should the main thread be blocked inside Update for an EditorWindow or elsewhere? Or is the exception regarding OnGUI a symptom of something else?
If I did decide to go the more difficult route of spawning other thread(s) is there a guide somewhere regarding what editor APIs classes are thread safe? To use light baking as an example: Could I block user input, iterate over all the light objects in a scene, and then iterate over all the light receiving objects in a scene and write data to them from several different threads (handling my own synchronization)? Or would I need to take a snapshot of the scene, serialize all objects to my own thread safe class implementations, and then serialize those back to the Unity objects once done?
Old post but I had the same issue using the solution 2 and fixed by using
function OnInspectorUpdate() {
// Call Repaint on OnInspectorUpdate as it repaints the windows
// less times as if it was OnGUI/Update
Repaint();
}