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


always returns null so I assume Unity doesn’t “work like that” under the hood.

My two-part question is therefore;

  1. Is there a way to execute GUI calls on the Unity main GUI thread from a worker?
  2. Or does a better/different method to achieve the same result using some aspect of Unity that I don’t know about exist?

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