Extremely poor UI performance on Android

My game project runs at 60 fps on my mobile device, but when I activate 1 UI panel that was previously deactivated [SetActive(false)] the framerate drops from 60 to 40 fps. When I set the panel back to false the fps go up till 60 again.

I’m just using Sprites and some uGUI text from TextMeshPro in that panel.

I hope you can help me. Thank you! :smile:

1 Like

Can you give some profiler screen shots? Specifically expanding the CPU tree view to the offending items?

You may find that you’re already sitting right on the 60fps mark and just a little more is causing issues.

I believe that Android forces vsync (regardless of vsync settings) as such if any frame goes over 16ms that frame will be 30fps (32ms) due to vsync. This can cause the average to be somewhere between 30 - 60 fps.

So for example, if without the UI panel you’re taking 15.8ms and if the UI panel takes 0.3ms then you’d start getting some frames at 30fps and some at 60fps, giving the average somewhere between the two.

You may want to include your Unity version, Android version and device type - these are often important details for specific issues.

As a rough guess, perhaps it’s something to do with the UI shaders. By default they do rect clipping, which can be a bit taxing on performance, especially if there’s a lot of UI elements involved. You could workaround the issue by downloading the default UI shaders, adding them to your project and removing the line color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
(This would prevent UI masks from working though).

Again, it’s just a rough guess - more information would be appreciated.

2 Likes

@NinjaCat what would give better performance between UI elements with a material with the modified UI shader you suggest, or the UI elements material set to none? Does none just use the UI default?

Thank you :slight_smile:

The modified one. If the material is not set, it should default to the UI Default material.

@NinjaCat thanks… some changes to make to my game then :wink:

Sorry for the late reply.

This are some screenshots running the game on my Samsung Galaxy S6.

Staying at Main Scene, without doing anything the game starts at 60 fps, then it goes down to 43-45 (without touching anything).

Now when I open my panel. The framerate drops to 30-33.

If I put the panel (it has scroll down in it) in a new project and run it on my android devices. Sometimes when I open it goes at 60fps and sometimes it goes at 40fps. It’s really weird. I hope you can help me.

1 Like

I have provided more information, would you still to the same as you recomend doing?

This looks like a fillrate/drawcall type issue to me, you’re GPU bound. Are you batching (dynamic and/or static) to reduce drawcalls? atlas all sprites, etc? Expensive shaders?

What about texture sizes? Are you pushing lots of large textures? Check the import settings for all textures being drawn and reduce them down to the smallest but usable size. Also ensure that any textures that can be compressed are (import settings).

What are your draw calls at?

I can send you the Unity Project with the menu. That sometimes runs at 40 and sometimes at 60fps.

The textures are not large (they’re all sprites). I have a lot of images.

Don’t trust fps, they go up and down quick.

No panel open:

Settings panel (not really expensive) 59-60fps on mobile (S6)

Shop panel (very expensive) 46-48fps on mobile (S6)

At the very least I’d give it a shot. If you’re not using any custom shaders/materials it should be as simple as importing the default UI shader into the project and removing 3 lines of code - thus a quick way to confirm/deny that the issue is in the shader.

I’ve seen performance drops in our app too but not directly.
We’re running at 60 fps for some time until thermal throttling happens.
Galaxy S6 is running hot quite quickly. UI only scene, 3 ~ 4 textures of 1024x682 (3:2), 22 drawcalls for the UI, a scroll rect to scroll through a list of items. (textures are unloaded / loaded after scrolling)

So is your S6 running hot?
What version of Unity are you using?
What happens if you lower the screen size to 1280x720?

I have downloaded the builtin_shaders-5.6.1f1.zip file. What should I do with that? Should I copy the files in it somewhere? Sorry, I’m new.

Find the UI shader folder which should be inside “DefaultResourcesExtra\UI” and then move the “UI-Default” shader into the project. Remove the line I’ve mentioned in the post above. After restarting the editor it should begin using the shader in the project instead of the builtin one for the UI.

It seems to work, now I get 56-58 fps! :smile: Thanks. But sometimes it drops to 38-40fps and when I disable the panel goes back to 60. If I enable it again fps go downj to 38-40 again :confused:

Any specific circumstances that cause the fps drop? Perhaps it’s the device throttling down?

I have this in all my active images:

I see that the drop happens when I’m some time with the panel open. My phone gets quite hot aswell. And then if I close the game and open it again insted of 60fps goes at 42 and with the panel open at 28-33.

Yeah, that sounds like thermal throttling - the phone is slowing down to avoid overheating.