Using the generic type 'IEnumerator' requires 1 type arguments

Hello,

So far i always used untyped IEnumerator, but as of late, im getting the above error using it. My implementation goes something like this:

class MyClass : MonoBehaviour {
    void Awake () {
        StartCoroutine (Test());
    }
    private IEnumerator Test()
    {
        yield return null;
    }
}

Which throws the error.
Now if i use a Type there, like so:

private IEnumerator<object> Test()
    {
        yield return null;
    }

…that works, but i will never ever want to return a non-null value, i will use this only to wait for next frame. Is there a better way to type a generic or is there a way to use untyped version (although when i think about it, the above is the same as the untyped version, isnt it)? Im basically looking for a BEST PRACTICE way to handle that specific use-case (only using it for yield return null as a delayed call or for staggered execution purpose), if anyone could chime in.

4 Likes

You most likely forgot to add using System.Collections; at the top of your file…