If you make 20 or more canvas in a scene of your game, one being giant (the player’s) and the others just small canvas to show some images on the screen in 3D, would it chanve the performance? Low the frames per second? Thanks.
After doing a significant amount of performance optimisation with canvases on my games, I’ve found the following
Having multiple canvases, even if they’re not dirtied still takes time for Unity to batch, which impacts performance.
When you have multiple UI elements in a single canvas and it needs to be redrawn (e.g a character profile card that also has it’s health shown as a slider). A scenario like that means that whenever a characters health changes, the slider updates and all other UI elements in that canvas as refreshed.
Splitting UI elements into multiple canvases as shown here actually does improve performance if you have multiple bits that don’t need to change (a mix of dynamic and static UI elements)
Ensure that your items have the Renderer Camera set up as outlined here, behind the scenes if no camera is set it will be Camera.main which does a .Find which is slow (and it may be triggered several times a second). For dynamic items, I’ve found a basic script that assigns the camera at run time reduced my load significantly (about 1ms)
Turning off the Graphics Raycaster is also another place I optimised. If these graphics don’t need user interaction you can turn it off so all raycasting is disabled for it
Also, if you have hundreds of game objects with their own canvas (e.g a tower defense game with each enemy having their own HP slider), this can be really taxing (as even with batches you’re still drawing multiple sprites for each slider). This has crept up before and the only real way I could limit it was to not show health bars all the time (show them when the player’s mouse is within a range)
I wanted to add that canvases are somewhat folders, of which all content is recalculated on dnt change within it. so having one giant UI might even be worse than 20 small ones.
Every object that exists in your scene hierarchy and is rendered to the screen costs some CPU/GPU resources. So yes, it will change performance a bit. Will it be noticeable? Probably not.
Hey, i’ve been looking to put typical healthbar in top of the characters of my scene, my problem is that it can be up to maybe 1000 objects at once, so i think puting a canvas for each one is not a good idea, do can i like add a canvas to my camera an have it show the healthbars only in the camera view?
More canvases = good!
One huge canvas = bad!
See: Divide up your canvases →
there are many other optimization tips!
And an official tutorial:
And a livestream about the same topic here: Unite Europe 2017 - Squeezing Unity: Tips for raising performance - YouTube