Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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,051
    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