Hacker News new | ask | show | jobs
by bzxcvbn 1461 days ago
> Delay instructions and waiting for other coroutines are implemented as type unsafe yield return values

Can you elaborate? I was under the impression that `YieldInstruction` is a well-defined type.

1 comments

You would use the base IEnumerator that yields object types. `YieldInstruction`s are a type that the Unity coroutine runtime will recognize but you can yield anything. Some have meaning like YieldInstruction, Coroutine, CustomYieldInstruction and others that Unity will recognize as some special command to wait before the next iteration. As far as I know there is no exhaustive public list. You can also just yield anything else from int to stream.

Yielding a final value that isn't a yield instruction is a technique to return a value from a coroutine. You can pull the final return value from the IEnumerator's Current property. Hacks on hacks but it gets the job done.