Yield return null in coroutine

Lets say i have 3 coroutines running and all of them uses yield return null, I want to know each frame will run all 3 of them, or only 1 of them ? Lets say each coroutine need 60 frames to complete, do i expect they will end within 60 or 180 frames ?

Thanks.

Each coroutine will run every update() loop.

So if you start three coroutines at the same time and they each yield return null 60 times then they will end at the same time (60 frames later).

1 Like

If you want to know more about the technical details of how coroutines work, this StackOverflow answer is a good reference: c# - How does StartCoroutine / yield return pattern really work in Unity? - Stack Overflow

Each time you create a coroutine, Unity adds it to an internal list of coroutines, and runs through them all on every frame.

When people say that coroutines are synchronous, they mean that one coroutine is updated at a time rather than truly running in parallel. However, rest assured they are all updated every frame (just try not to stay in one coroutine for too long because you’re blocking the rest of the application).

Bookmark this link as you’ll probably want to keep coming back to it every time you wonder when coroutines are running :smile: :Unity - Manual: Order of execution for event functions