docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class EditorCoroutine

    Manages and executes coroutines within the Unity Editor environment.

    Inheritance
    object
    EditorCoroutine
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.EditorCoroutines.Editor
    Assembly: Unity.EditorCoroutines.Editor.dll
    Syntax
    public class EditorCoroutine
    Remarks

    The `EditorCoroutine` class enables running coroutines without entering Play Mode, providing a way to perform asynchronous tasks within the Unity Editor. This feature is beneficial for developing editor tools that require non-blocking operations such as waiting on web requests, IO operations or for user inputs.

    This class interacts with the EditorApplication.update event to advance coroutine execution. Coroutines started with `EditorCoroutine` can be controlled via the EditorCoroutineUtility methods, which offer lifecycle control such as stopping or pausing operations.

    **Tip**: `yield return null` is a way to skip a frame in the Editor.

    Important Considerations:

    • Be aware of editor performance when using `EditorCoroutine` for intensive tasks; aim to optimize long-running operations to avoid impacting the Unity Editor's responsiveness. Remember that coroutines execute synchronously on the main thread in between of yielding.
    • Coroutines automatically stop if the owner object is garbage collected, thanks to a `WeakReference` ownership check.
    • No explicit update calls are needed as this class handles its integration into the editor's update loop.
    Examples

    The following example demonstrates how to use `EditorCoroutine` to increment a counter over time:

    using UnityEditor;
    using UnityEngine;
    using System.Collections;
    

    using System.Collections; using Unity.EditorCoroutines.Editor; using UnityEditor; using UnityEngine;

    public class EditorCoroutineExample : EditorWindow { int m_Counter; EditorCoroutine m_Coroutine;

    [MenuItem("Window/Editor Coroutine Example")]
    public static void ShowWindow()
    {
        GetWindow<EditorCoroutineExample>("Editor Coroutine Example");
    }
    
    void OnGUI()
    {
        if (GUILayout.Button("Start Coroutine"))
            m_Coroutine = EditorCoroutineUtility.StartCoroutine(IncrementCounter(), this);
        if (GUILayout.Button("Stop Coroutine"))
            EditorCoroutineUtility.StopCoroutine(m_Coroutine);
        GUILayout.Label("Counter: " + m_Counter);
    }
    
    IEnumerator IncrementCounter()
    {
        for (int i = 0; i < 10; i++)
        {
            m_Counter++;
            Debug.Log("Counter: " + m_Counter);
            Repaint();
            yield return new EditorWaitForSeconds(1);
        }
    }
    

    }

    See Also

    Coroutines
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)