Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Where are Editor Coroutines in 2019.3.5f1?

Discussion in 'Editor & General Support' started by astracat111, Mar 14, 2020.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    I recently updated my editor to 2019.3.5f1 and I can't find Editor Coroutines in the Package Manager. I'm getting thrown all kinds of errors for using them previously.

    EDIT: I'm updating from 2019.2.17.
     
  2. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    I know this is a rare case to need this, but for anyone else looking for Editor Coroutines that stumbles on this thread, here's what you do.

    Download this asset:
    https://assetstore.unity.com/packages/tools/utilities/editor-coroutines-27373

    Update the Process() method in EditorCoroutine.cs to this so that it supports yield return false; and yield return true; (else doesn't return an error).

    Code (CSharp):
    1. static bool Process(EditorCoroutine coroutine)
    2.         {
    3.             object current = coroutine.routine.Current;
    4.             if (current == null)
    5.             {
    6.                 return false;
    7.             }
    8.             else if (current is WaitForSeconds)
    9.             {
    10.                 float seconds = float.Parse(GetInstanceField(typeof(WaitForSeconds), current, "m_Seconds").ToString());
    11.                 coroutine.currentYield = new YieldWaitForSeconds() {timeLeft = (float) seconds};
    12.             }
    13.             else if (current is WWW)
    14.             {
    15.                 coroutine.currentYield = new YieldWWW {Www = (WWW) current};
    16.             }
    17.             else if (current is WaitForFixedUpdate)
    18.             {
    19.                 coroutine.currentYield = new YieldDefault();
    20.             }
    21.             else if (current is AsyncOperation)
    22.             {
    23.                 coroutine.currentYield = new YieldAsync {asyncOperation = (AsyncOperation) current};
    24.             }
    25.             else if (current is EditorCoroutine)
    26.             {
    27.                 coroutine.currentYield = new YieldNestedCoroutine { coroutine= (EditorCoroutine) current};
    28.             }
    29.             else
    30.             {
    31.                 coroutine.currentYield = new YieldDefault();
    32.             }
    33.             return true;
    34.         }

    Update this method so that you don't need to have a reference to a class (if you're using static methods you'll need this):

    Code (CSharp):
    1. public static EditorCoroutine StartCoroutine(IEnumerator routine, object thisReference)
    2.         {
    3.             CreateInstanceIfNeeded();
    4.             return instance.GoStartCoroutine(routine, thisReference);
    5.         }
    Update it to this:

    Code (CSharp):
    1. public static EditorCoroutine StartCoroutine(IEnumerator routine)
    2.         {
    3.             CreateInstanceIfNeeded();
    4.             return instance.GoStartCoroutine(routine, new object());
    5.         }
    Now coroutines will work in editor scripts if you use them:

    Code (csharp):
    1.  
    2. using EditorCoroutines;
    3.  
    4. public static class myClassName {
    5.    
    6.     public static void RunCoroutine() {
    7.          EditorCoroutines.EditorCoroutines.StartCoroutine(HelloWorld());
    8.    }
    9.  
    10.     private static IEnumerator HelloWorld() {
    11.       UnityEngine.Debug.Log("Hello One");
    12.       yield return new WaitForSeconds(2.0f);
    13.       UnityEngine.Debug.Log("Hello After Wait.");
    14.    }
    15.  
    16. }
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,118
  4. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    624
    Huuuh, I wonder why that is....

    Doing it with this asset essentially just does the same thing...but it makes no sense to me right now why I couldn't find it. It's on my laptop but not my desktop.
     
unityunity