Unity’s Coroutine System

Ben Pielstick
Mar 30, 2021

Until Unity’s new Data-Oriented Technology Stack is ready, the way Unity handles looping through tasks outside of the main game loop is through Coroutines.

All the ways we can start a Coroutine

What a Coroutine basically does is run an iEnumerator method which can use the yield keyword to break out of a loop, either forever or for a set period of time.

yield is what makes Coroutines useful

Using this feature provides for repeated actions outside the main Update loop, which is great for any kind of scheduled or regularly reoccurring events during gameplay. Unfortunately this feature doesn’t spin up additional threads, so this won’t improve performance on CPUs with multiple cores. Unity has a new Entity system in progress though, which promises multi-threading as well as a range of other improvements.

--

--

Ben Pielstick

Game developer with over 12 years of experience, mainly focused on MMOs.