Optimizing Coroutines

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.

--

--

Unity Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store