Is there a way to run a coroutine in the Editor?

I have this thing that’s firing a job then completing it when the inspector is changed and it currently uses OnDrawGizmos. Want to replace it with something cleaner.

Putting an [ExecuteAlways] on your script is essentially the same mechanism that OnDrawGizmos is doing. It’s not a coroutine, but it does force Unity to call your stuff even when you are just staring at the Scene view.

Personally, I try to avoid as much ExecuteAlways code as possible. It definitely causes more work for the GPU and CPU, bogging down your editor performance. But sometimes there’s really no other way.

There is a package for this: About Editor Coroutines | Editor Coroutines | 1.0.0

1 Like

What I found is that it calls update only on scene update. These happen when the mouse hovers it or any other operations. In contrast, EditorApplication.update += will update very frame.

am I wrong in thinking this is what OnValidate is for?

Yes that’ll take care of the detect inspector change part. Not the coroutine part.

aargh… I think I’m getting it… so having had/detected a change occur, you then want something to happen for a certain amount of time, at a set interval (eg per frame for a while)?

Did you miss this post of mine that literally lets you run a coroutine in the editor?

2 Likes

Yes.
We figured it out eventually: running the coroutine by hand by calling .MoveNext() on each cycle.

1 Like

Have you got me blocked or something?

1 Like

Spiney wrote:

Have you got me blocked or something?

I hope not! But it does feel like a case of not reading your posts… but why would anybody block a Spiney?!