Basics of Optimization in Unity

Unity Profiler Course

Using the unity Profiler, we can optimize the game but how do we optimize the code to optimize the game.

We can use Profiler inside the code to seal a set of code which can be used to confirm the frame spike from that set of code.

Here, Vector3 and GameObject both use new keyword but the Vector3 doesn’t cause frame spike as much as GameObject while using new keyword because Vector3 is a Struct which is a value type and does not allocate memory while GameObject is a Class which is a reference type and allocate memory. So you should cache the new keyword when using with reference types to optimize code.

It is also better to use List rather than Array as it is more performance friendly and easy to navigate and use.



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