Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

where is yield return new StartCoroutine() in 2019

Discussion in 'Scripting' started by vfxjex, Feb 13, 2020.

  1. vfxjex

    vfxjex

    Joined:
    Jun 3, 2013
    Posts:
    93
    Code (CSharp):
    1.     IEnumerator Test()
    2.     {
    3.         yield return new StartCoroutine(CoroutineTest());
    4.     }
    5.  
    6.     IEnumerator CoroutineTest()
    7.     {
    8.         yield return null;
    9.     }
    Above is a simple code of yield return new StartCoroutine but it could not be found when using yield return new.
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    StartCoroutine
    is a method on
    MonoBehaviour
    , not a type. Using
    new
    here is incorrect and causes C# to look for a type, which it can't find. Remove it and the code should work fine.

    You do need to use
    new
    with
    WaitForSeconds
    and other yield instructions, those are types and not methods and require a
    new
    to instantiate.
     
    Ryiah likes this.
  3. vfxjex

    vfxjex

    Joined:
    Jun 3, 2013
    Posts:
    93
    hahaha sorry my bad...
    Thanks Adrian