- Home /
Is multiple canvases for non changing ui elements better for performance?
Kind of a noob question. My game is 100% in unity's UI but it runs hot sometimes on mobile devices. I have only 1 canvas. Should I break up my UI into multiple canvases for elements that have no animation? Will that increase performance or am I better off with just 1?
Answer by DaDonik · Apr 28, 2017 at 07:51 AM
If anything inside a Canvas is changing, like changing the position of an UI element, or changing some text, the Canvas mesh has to be rebuilt. Depending on the complexity of your Canvas, this can result in 65535 vertices that have to be rebuilt per frame. You can seperate you UI into several Canvases, which i totally recommend, to minimize what needs to be rebuilt.
Regarding the device running hot: This can totally be the result of rendering 60fps. I had phones that ran hot with 60fps and not a lot to render at all. Try setting the Application.targetFrameRate to 30.0f. If your game is UI only, 30 fps should be fine i assume.
$$anonymous$$ay I ask, for example, if I was to build like Instagram in unity UI, which set up would be recommended?
Just in case you're not familiar with Instagram, the yellow box would be a horizontal scroll rect (called stories) while the green box is a vertical scroll rect (the feed).
The stories scroll rect is, in fact, a child of the feed but because it can scroll would it not be better to have the be its own canvas? Or would it be better like v2 where all the scrolls are grouped under 1 canvas?
Thanks for your time!
Given the low amount of UI elements in both of these screenshots, i can't really imagine that your overheating issues come from rebuilding the Canvas. It really depends on how many scrollable items you have in those scrollviews. A Canvas can not have more than 65535 vertices and every character takes 4, so does every image, button, etc. So that limit should also be part of your decision. Generally i would tend to SetUp #1. It will take 3 drawcalls, because you have 3 Canvases, but that is not a problem at all. You will certainly save processing time when scrolling, even if it might not be noticable, depending on the amount of UI elements per Canvas. Better save then sorry =)
Have you tried changing Application.targetFrameRate? Note that Unity only allows either 30 or 60 fps on mobile devices, at least that was the case last time i tried setting the targetFrameRate. In theory that will split the heat your device exhausts in half...sort of.
thanks for your answer!
its been set to 30 fps from the beginning but I so have a fair amount of animated textures so im guessing thats the source of my problem and im trying to trim that fat on that.
Answer by AdamAlexander · Apr 28, 2017 at 06:03 AM
I'm not sure I completely understand what you're asking here but I don't think it would make any difference to performance if you split your UI over multiple canvases.
Normally I will only split my UI into multiple canvases because it made sense to organise them that way.
If you have lots of transparent ui pieces rendered over the top of each other that could potentially cause performance problems on mobile.
But having multiple ui objects on one canvas I dont think so.
*Edit Looks like I'm wrong about this, but I would confirm that this is causing your performance issues with the profiler first, as there are other reasons your UI may be performing badly. I think splitting your canvases as a hard and fast rule would be premature optimisation.
Have you seen: https://unity3d.com/learn/tutorials/temas/best-practices/guide-optimizing-unity-ui
Your answer
Follow this Question
Related Questions
Can the UI system effectively manage dozens of frequently update sprites? 0 Answers
Better way to make big 2D Game. UI Canvas, Transform calculation, animation 0 Answers
1 UI Text vs 2 UI Text 1 Answer
camera space performance/ aligncanvasrecttransformwithcamera 0 Answers
UI performance on mobile. FPS drops 0 Answers