Basics of Optimization in Unity

Yesterday's example should show why it’s important to cache your coroutines, but it’s important to cache variables as well.

The importance of caching GetComponent:

New isn’t always better!

Oftentimes, when we’re trying to move a gameObject in a direction, we use a new Vector3, while a Vector3 is a struct and doesn’t incur any garbage collection, it’s still a bit more optimal to cache a Vector3 into a variable, modify it, and then assign it back to the transform so you just change 1 variable instead of potentially creating a constant flow of new Vector3s.

Caching is especially important with classes like GameObjects. When you create a new gameObject, always try to cache it and object pool if possible. Caching it alone will save a lot of memory.

Precise PinPointing Pesky Performance Problems with Profiler!

Use Visual Studio to check if something is a class or struct

Cache those yield returns!

Better RayCasting methods are available

Camera.Main is a hog!

Lists vs Arrays

Structs vs Classes



cartoonist, game artist, and wanabe gamedev.

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