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

AWS Lambda in GoLang — The Ultimate Guide

Understanding numpy array

As a software development team lead, i had my share of headaches with too clever by half bro’s…

March LeetCoding Challenge 2021 — Day 6:Short Encoding of Words

SAP Freshers Hiring For Quality Associate Position | Apply Now

Program Memes

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

Top 10 most important MUN terms-Part 2

Can you recognise employees with a limited budget? // Work Points Play

K2 Spice Paper Sheets and Spray

Why Boxing has Changed Forever