Search Unity

Extremely poor UI performance on Android

Discussion in 'Android' started by Finijumper, May 25, 2017.

  1. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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! :D
     
    mimiCryMuffin likes this.
  2. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    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.
     
  3. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    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.
     
    Haze-Games and larku like this.
  4. stevenatunity

    stevenatunity

    Joined:
    Apr 17, 2015
    Posts:
    114
    @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 :)
     
  5. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    The modified one. If the material is not set, it should default to the UI Default material.
     
  6. stevenatunity

    stevenatunity

    Joined:
    Apr 17, 2015
    Posts:
    114
    @NinjaCat thanks... some changes to make to my game then ;)
     
  7. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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.
     
    mimiCryMuffin likes this.
  8. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    I have provided more information, would you still to the same as you recomend doing?
     
  9. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    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?
     
  10. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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.
     
    Last edited: Jun 17, 2017
  11. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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)

     
  12. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    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.
     
  13. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    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?
     
    Last edited: Jun 21, 2017
  14. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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.
     
  15. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    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.
     
  16. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    It seems to work, now I get 56-58 fps! :D 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 :/
     
    Last edited: Jun 21, 2017
  17. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    Any specific circumstances that cause the fps drop? Perhaps it's the device throttling down?
     
  18. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    I have this in all my active images:
     
  19. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    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.
     
  20. NinjaCat

    NinjaCat

    R&D Minion

    Joined:
    Aug 22, 2013
    Posts:
    69
    Yeah, that sounds like thermal throttling - the phone is slowing down to avoid overheating.
     
  21. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    In another phone when I open the game, sometimes yes and sometimes no happens this:


    Also all the phones that I've tried the game in get really hot.
     
  22. lucianoreul

    lucianoreul

    Joined:
    Apr 6, 2017
    Posts:
    2
    @Finijumper It looks like this post has been forgotten. Btw, try removing all the "image" components of the UI elements that did not need to carry sprites, this solved for me. Somehow they are causing GPU drive delay (gfx.WaitForPresent).
     
    Last edited: Aug 21, 2018
  23. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    I'm currently working on another project and with only a couple of images and buttons on the UI I can't get stable 60fps framerate. Is there any solution to this after all these years?
     
    mimiCryMuffin likes this.
  24. Baschti-aus-s

    Baschti-aus-s

    Joined:
    Jan 6, 2020
    Posts:
    9
    I was facing the same issue as the TO and tried some stuff in the past few days to solve it. Here are my experiences.

    First, to understand how the Unity UI system works, read this tutorial:
    https://learn.unity.com/tutorial/optimizing-unity-ui#5c7f8528edbc2a002053b59f


    In my case, I got a scroll view with a bunch of images that causes the frame drop. Simplified, it looks like this:



    Activating this menu causes a frame drop on a mobile device from 36FPS to 22FPS. My menu needed 75 batches to be drawn (read in the article above, what this means).

    To reduce the number of batches in my case, the most effective step was to combine all sprites which are used to one sprite atlas. (Solved batch breaking reason: “Different Texture”).

    Doing so, I ended up with 14 batches.

    Furthermore, I changed the semi-transparent background colour to a solid background colour without any transparency.

    The two steps above improved my FPS rate from 22FPS to 26FPS. A little bit better, but still worse.

    An additional step to improve performance of UI could be the use of a material with a lighter shader, like “Sprites – Default” instead of the “Default UI”. This step is similar to the approach NinjaCat was talking about and it got the same disadvantage: The masking is not working anymore. So in my case, this is not an option, because masking is important for my scroll view to work.


    For me, the last step do the trick: Even if the UI covers a large part of your scene using a fully opaque image, Unity will render the whole 3D scene behind the UI first and then overlays the UI components. With this information, I changed the UI appearance to this:



    Now, it covers the whole screen. When activating the menu, I use the culling mask property of the main camera (https://docs.unity3d.com/ScriptReference/Camera-cullingMask.html) to stop rendering all the stuff in the scene, which is hidden by the UI anyway.

    With the new approach, I was able to improve my frame rate to 40FPS when the menu with the scroll view is open. Other menu components without a scroll view runs at 60FPS now instead of 32FPS before.
     

    Attached Files:

    Last edited: Mar 30, 2022