- Home /
Threads in EditorScript?
Is it possible to use Threads in Editor scripts? My problem is I have some editor functions that can be quite time consuming. What I want to achieve is that Unity stays responsive or at least shows a status bar while performing theses tasks. At the moment the function is started from and EditorWindow.OnGUI(), so the function blocks unity completly. Even Debug.Log's won't show up in the Console (although they do in the log file itself). Is there any way I could at least show a status bar? (like the one that shows up on import)
Answer by Mike 3 · Jan 14, 2011 at 01:38 PM
As long as you don't call into the unity API from the threads, then it's fine. The issue is that a lot of things do it, for example
if (myTransform != null) {
will throw exceptions at you, as annoying as that may seem.
For progress bars, you can use EditorUtility.DisplayProgressBar :
http://unity3d.com/support/documentation/ScriptReference/EditorUtility.DisplayProgressBar.html
or one of the other progress bars in the class
Thanks, don't know how i was able to overlook that one.. ;)
Answer by Statement · Jan 14, 2011 at 01:31 PM
Yes, you can use Threads in EditorScript. Just make sure to make proper synchronization between the threads.