Nerd For Tech
Published in

Nerd For Tech

Optimizing Coroutines in Unity

Coroutines are extremely useful for any time specific function, however when one uses the yield return new function, that uses a lot of garbage allocation resources as every time the new keyword is used, Unity has to build that new thing on the spot.

This is where caching WaitForSeconds comes in. Think of Caching the WaitForSeconds as a Hot-N-Ready WaitForSeconds routine just waiting for anyone to pick it up and use it!

Since the WaitForSeconds is already built and available, when the coroutine is run, Unity doesn’t have to go through any more extra steps and potentially slow your game down!

The key takeaway here is an important concept in optimizing code is caching your data! Hope it helps!

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

The Reasons of Using UE5 for Project EVO

How-to setup a semi-automated release process with GitHub action/workflow

Four best practices for Gunicorn deployed in production

Azure Service Bus Session Enabled Message Processing

CS371p Week 4

Continuous Integration with Laravel and GitHub Actions.

The Vanishing Thread and Postgresql TCP Connection Parameters

Q&A: How Eventbrite prioritizes developer productivity

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
Esteban Ibarra

Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.

More from Medium

Cross-platform Input Controller in Unity

Tips to Improve Unity Performance

Virtual Cameras w/ Cinemachine in Unity 2020 — Part 7

Code Optimization- Game Dev Series 145