In my game there is lots of characters each having name + title above the head, when camera is moved ALL canvases are rebuilt, even if nothing is actually changed??? Why and how can i prevent Unity from doing it. I tried disabling all layout elements on the canvas, yet it still rebuilding. This causes huge and unnecessary performance drops.
We have a similar issue using Camera space canvases. Would really like to see a response from unity as I can’t really find anything on this and the performance when the camera moves can be terrible with more complex UI.
Might be a bit dated since it’s from 2017, but this is one of my favourite Unite talks and it relates to UI performance.
I’m not in UI team, so I don’t know if the statements are still true, about the UI hierarchy getting dirty, but my first thought was this.
I watched this and there is a lot of good info in it but it does not quite resolve the issue we ran into. It’s the fact that the entire canvas rebuilds every time the camera most even slightly
I’ve been thinking about the solution and the only one i currenly kinda looking at is to cimpletely abandon the CanvasRenderer subsytem. I am going to use my own text rendering solution instead of TMP and my own Image class, this should be enough for building primitive UI’s.
This is ridiculous Unity forces me to do this, but currently i see no easier way
are you doing the same mistake like me and using canvases to draw titles on top of char’s heads?
2 better solutions:
- (didn’t try it, but sounds like the best) use regular textmeshpro (the 3d one, not the UGUI component)
- simply merge all texts into the same canvas. maybe do it directly at edit-time or have a builder that creates those texts at runtime and uses Camera.WorldToScreenPoint from each object to display them on screen (use an llm for details), so you won’t need to care about resizing them, and you can use an overlay canvas instead of a camera canvas (I think it’s lighter on performance). you can keep an overlay canvas just for the titles, if you want – nobody prevents you from having many root canvases
- I tried and it didn’t yield the results desired. Idk why but tests showed approximatively same performance as with regular canvases. Not to add it prevents me from building even relatively complex UI elements.
- I’ve been experimenting with it too, though i not managed to get it working. For some reason it renders my UI differently if it is located in one common canvas instead of one canvas per element. My UI is using pixel fonts and it was very noticible. I did not managed to troubleshoot the issue yet and kinda abandonend the effort so far, being busy with different tasks.