I’m making an editor script to do some stuff to a bunch of our scenes.
Roughly:
- Open scene
- Save it as something else
- Edit the new scene
…over and over again.
It works fine, but it completely locks up the UI for that time. You can’t even see the levels opening and closing, and debug messages don’t come through until everything is done. And I completely understand that.
But how can I get around it? You can’t run coroutines in editor scripts as far as I can tell.
I tried using http://wiki.unity3d.com/index.php?title=CoroutineScheduler, which actually works occasionally. After each action I put yield return 0;
which updates the UI.
The problem is that most of the time it doesn’t work. I can’t figure out why, but it’ll get to a yield statement and basically just stop.
I’ve confirmed that I do carry on running _scheduler.UpdateAllCoroutines
, so that isn’t the issue.
So is there a better way to give the Unity UI enough time to show the new scenes opening etc before I carry on what I’m doing?
Thanks.
p.s. A lot of what I’m doing requires it to be on the main thread, so I can’t just throw everything into the background.