I’m working on an Android project, and everything was silky smooth until I added UI. Now the game is stuttering with just a few UI objects. Is there something obvious I’m doing wrong?
The game starts with a simple “Menu” Scene, with just a camera and a canvas with a few UI objects (two texts, one button). This scene itself is slow to respond when clicking the button (which loads the “Game” scene)
This next scene has a dynamic text element that get updates every update tick, and reducing rate at which I’m setting the textElement.text value doesn’t help any performance.
Eventually when the game is over I set the “GameOver” UI element to active, which is just a UI text and button which is disabled during gameplay.
Any idea what I can do to improve performance?
I’ve read that using “BestFit” on UI text is poor, but none of my text elements have best fit checked.
A couple of suggestions…I was having the same problem, I did a comparison on duplicate projects/UI 4.5 UIToolkit vs.4.6 UI…and was losing up 30fps… a huge and scary drop…
1st). Turn off SpritePacker and use this [TexturePacker]…it is well worth it!
You have to think what that service*(SpritePacker)* is trying to do every frame, it is very complicated, especially with dynamic objects/font size variants…OVERHEAD!!
Do it once with TexturePacker, not every frame…simple
2nd). Come up with some sort of naming convention, pretty please…
@ : Hmm, that’s an interesting idea, and I can see how it would be helpful. The thing is I’m not using any custom graphics, just a single font file and that’s it. Is there an option to use a texture atlas instead of a font file in the UI Text objects?
@phil-Unity : I will do that, thanks! I just realized I’m on an older version of 4.6, so I’ll update first. Who knows maybe that will do something.
I did some more testing and found that removing the line of code that sets a UI Text text value fixes the problem of Canvas.BuildBatch() taking so much time. Previous tests showed that reducing the update rate didn’t affect it much, so perhaps I didn’t reduce it enough or something, but removing it altogether works. I guess that makes sense, as it needs to rebuild every time the text is changed…? Now that I know what the root of the problem is maybe I can find a better way. Is there any existing ways to have dynamic text that is “faster”? I’ll create a simple project and submit that as the bug report. EDIT: The simple project reports Canvas.BuildBatch() taking only 3.5% time. So it must be something with the nesting of UI objects. After additional testing it seems removing the Panel UI object speeds everything up, so this is the offending object. Very strange.
I’ve removed the panel object from my UI and everything is going smoothly, even while setting text on a textfield every update.