unitytips: Editor Coroutines

Recently, I was doing a small experiment trying to run an CHIP-8 emulator inside the Unity Editor inspector window and for that I needed to update from times to time the inspector.

Initially I tried to use EditorApplication.update, but as it is only called when something changes in the inspector, it ended up not serving this purpose.

It was then that I discovered this official Unity package: Editor Coroutines

The Editor Coroutines package allows the user to start the execution of iterator methods within the Editor similar to how we handle Coroutines inside MonoBehaviour scripts during runtime.

Usage

At this time we cannot use any of the yield classes present inside the Unity Scripting API, like WaitForSeconds and WaitForEndOfFrame, except for the CustomYieldInstruction.

However, there is a specific yielding class for wait seconds on Editor: EditorWaitForSeconds

In my case, I used the yield return null to skip a frame within the Editor and get the refresh rate that I would like.

post image

The result of using the EditorCoroutineUtility.StartCoroutine



More details in the official documentation: Editor Coroutines

Loading comments...
Tutorials

Articles

Labs