- Home /
How can I invoke code on the Editor GUI thread from a worker?
I've got an editor build script which needs to copy a substantial amount of files across a network. I might be missing something but it doesn't seem that I can use Co-Routines since the editor scripts are not running as MonoBehaviours so I'm resorting to kicking off a worker thread to do the copying.
Now, back in WPF land I'd now use a SynchronizationContext object to invoke GUI updates like a progress bar on the main GUI thread but
SynchronizationContext.Current
always returns null so I assume Unity doesn't "work like that" under the hood.
My two-part question is therefore;
Is there a way to execute GUI calls on the Unity main GUI thread from a worker?
Or does a better/different method to achieve the same result using some aspect of Unity that I don't know about exist?
Answer by Slobdell · Jan 07, 2014 at 09:18 PM
I've had this issue, I don't believe you are allowed to do anything to the gui from a thread other than the main thread. I've only found some sloppy ways around this but you should be able to use a middle-man variable. Have you're gui on the main thread be reading status from a thread-safe variable in the main thread, while your worker thread updates the status variable from the worker thread
Thanks for your reply; I suspected I might have to do something like that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
SearchableEditorWindow 2 Answers
C# Editor script in Unity 1 Answer
Threading in Unity is "...virtual" ?! :D 1 Answer
How to make a editor script that sets the values of serialized variables in the editor 1 Answer