Optimizing the UI

A little bit of a boring topic, but a necessary one! A few things I’ve learned can help get a bit of performance out of your game through optimizing the UI!

— — —

First we are going to go over two types of UI elements, Active canvas items and Static canvas items.

What is important to know is that when things change on the canvas, which is called dirtying the canvas, Unity has to redraw everything within that canvas. That sounds like extra data usage that we can avoid and we can do that by simply dividing active elements, those that change, and static elements, those that do not change, into separate canvas groups. By doing this, we can avoid Unity redrawing static canvas items and thus increase performance.

— — —

The second thing we can look at is Raycast Target on image objects. By default Unity enables this for every image and we definitely do not need this on for anything that does not need to be clicked on. Make sure to turn this off when it isn’t needed!

— — —

The last thing for now is that whenever possible, hide the entire canvas rather than hiding individual GameObjects in the canvas. Unity uses less processing on hiding a canvas rather than a GameObject!

Anyway again, a bit boring but definitely optimization that can easily be done for any project and everything counts!

See you next post!