I don't understand enough about a method with coroutine return type

So why if we change the return type of a method from IEnumerator to Coroutine, we are “capable” to yield return (to make it wait until finish) or just return (to run the method asynchronously). I don’t understand really well and deeply about it. Am I missing something?

1 Like

An IEnumerator simply a container… like a tube full of pringles… yield return simply tells the StartCoroutine process to look for the next pringle. It’s flaw is that it requires at least one yield return.
A Coroutine is a special class that takes this into account, allowing both the tube of pringles and a single chip.

4 Likes

I love how you use a metaphor as same as Sam described and you expand it, but I still have no real a deep understanding about why you call it is a “special class that takes this into account, allowing both the tube of pringles and a single chip”, why coroutine return type allows it. If anybody can explain it in more detail or break it down, I would be very grateful.

2 Likes

TBH, I don’t understand the internal workings either. It’s something introduced by Unity’s implementation of C# (you won’t find the Coroutine class in the .NET library, which is where we get IENumerators). Sometimes the answer literally is “because that’s the say Unity made it”.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms