Fast Prototyping in Unity: Co-routines

Do more with less code and greater flexibility

Yvens Serpa
SUPERJUMP
Published in
11 min readApr 15, 2021

--

Computer programs and digital games are composed of many algorithms, tasks, and processes that create the expected software experience. You can execute these operations in parallel, meaning at the same time or in a sequence (also known as in serial).

Although most non-technical users would assume that executing operations in parallel is always better, this approach has its shortcomings.

Synchronization is one of them. Even if the physics system in a game executes in parallel, it must be synchronized with the graphics system before updating the image displayed on the screen, as an example.

On the other hand, executing all tasks in sequence might be slow and inefficient. Thus, there is a clear trade-off between both approaches which expands further than just technical challenges and performance. To be fair, even within the realm of Serial & Parallel, there are multiple strategies.

Coroutines are part of this discussion. They are computer programs that can halt their execution until another triggers their continuation. Coroutines have their own individual stack, meaning they act as if they are individual programs on their own.

--

--

Yvens Serpa
SUPERJUMP

I'm a Brazilian teacher currently working at Saxion University (Enschede, NL) for CMGT. I write every day for education, programming, and as a hobby. [@yvensre]