Optimizing Coroutines

Niraj Karki
Mar 21, 2022

--

Unity Profiler Course

A coroutine allows you to spread tasks across several frames. In Unity, a coroutine is a method that can pause execution and return control to Unity but then continue where it left off on the following frame.

This is the standard example of coroutine which tells the program to stop the processing of loop for 0.5 sec before continuing from the same place.

Here, this is the optimized version of coroutine which bounds the use of new keyword to a single time decreasing the Garbage collection every time the new keyword needed to be used.

--

--