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.
Answer by Hellium · Jun 12, 2019 at 06:05 AM
You most likely forgot to add using System.Collections;
at the top of your file....
In fact you are right. Thanks a lot, i'm quite surprised!
EDIT: to further explain what was going on: using System.Collections.Generic will use the generic IEnumerator, which requires a type. using System.Collections will use IEnumerator which does NOT require a type.
Your answer
Follow this Question
Related Questions
Mob.opponent' is a `field' but a `type' was expected help please! :) 1 Answer
How do I give an object a script component of a type specified by the calling source? 1 Answer
Cannot convert method group expression to IEnumerator 1 Answer
IEnumeration dont do the next lines after the yield return 0 Answers
Why doesn't the prefab destroy ? 0 Answers