Simple optimization tips for Unity

Let’s go over some simple optimizations for Unity

1. Cache your data

One of the most common optimizations are to ensure that expensive calls are cached. Examples of these are GetComponent or FindObjectWithTag:

A maybe less obvious caching is that of WaitForSeconds used in coroutines:

2. Debug.Log

Debug.Log has a lot of overhead and it is very important all of them are removed when no longer needed. To be on the safe side that there are no Debug.Log calls in a release build you can add the code below to one of your scripts:

3. Strings

This is not an optimizations tip but more of a heads up. It might be surprising but using strings can build up a lot of garbage collection. As strings are immutable, manipulations to a string will result in memory allocation for a whole new string. Bottom line, do not add string manipulations to your Update method.

4. UI

All objects under a canvas is handled as one atlas so if one object is changed all other objects under that canvas also needs to be redrawn. To improve performance split up the different areas of the UI as several different canvases. To keep the hierarchy tidy just add all canvases as children of an empty game objects

Pixel Perfect is a setting which forces UI elements to be drawn with direct alignment to the pixels on the screen which often makes the UI look sharper. This however does not work well with scroll rects and has a huge performance impact so ensure that the canvas that holds the scroll rect has this feature disabled

Good luck!

--

--

--

Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Vacuuming ‘dead tuples not yet removable’ in PostgreSQL and other tales.

Commands useful for Application Administrators in linux server systems for troubleshooting issues…

Requirement Elicitation – Meaning, it’s Purpose and it’s techniques.

Dockerize Angular Application (with Nginx and multi-arch image)

Deploy a ClamAV Docker container with AWS CDK on ECS

Performance test case in radix tree __alloc_fd

Adding reflections to your scenes in Unity

Part 2— The Mobile Client. How to build a real time data sync, multi platform app with Cordova

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
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

From C Student to CSUN student

CS373 Spring 22 Blog #3: Daniel Dominguez Arroyo

How software development taught me about neuroplasticity

CS373 Spring 2022: Dani Amir