Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sluggish GUI - how to optimise?

Discussion in 'UGUI & TextMesh Pro' started by SoftwareGeezers, Nov 9, 2015.

  1. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    I've a reasonably complex main menu and customisation UI with several panels layered and scroll views. I've packed all sprites with the sprite packing tag 'UI'. When run on a 2013 Nexus 7, the refresh is really sluggish. There are about 90 batches.

    Before using Unity's new GUI, I've used NGUI and it gives much faster results, drawing everything in a handful of batches. Is there an optimisation step I'm missing?
     
  2. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Is there literally nothing? Is Unity's UI system just slow to the point of being useless for anything other than a message box? Why include scroll views and the like if they can't be drawn at a usable rate? Or is Unity UI only intended for PC? :confused:
     
  3. henkjan

    henkjan

    Joined:
    Aug 1, 2013
    Posts:
    146
    Are you running Unity 5? Because than you can try the Frame Debugger to see the draw calls. In my case I lower the draw calls by changing the design a bit (not using masks anymore)
    But in my experience uGui isn't very fast (yet).
     
  4. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Yes, 5.2.2. But not using masks and such, you can't create a decent modern interface. NGUI (and maybe other UI assets) has already set the bar for what's possible at a decent rate. There's no point adding UI features to Unity if they are effectively unusable. The end result is leading me down a dead-end, investing in learning the new tools only to find they aren't good enough and facing refactoring my entire front end to NGUI.

    Anyway, I'll give the frame debugger a look at some point. Never used the detailed debug features before.
     
  5. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Any reasons you decided to switch from NGUI? Leap of faith?
     
  6. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    It's actually a team mate developing the UI and it made sense. There was no reason to think the new UI would be released in a nigh unusable state, and no reason to avoid it, while the Unity UI has real documentation whereas NGUI is a pig to learn although very capable. A community supported, officially supported UI is the ideal. I'm still perplexed why a scrollable list can reduce drawing to a crawl.
     
    zyzyx likes this.
  7. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    How many items in the scrollable list? Have you ruled out any game-related initialization for each item in the list? Just trying to hone in on what might be going on, while you wait for any official Unity support that could possibly be roaming this thread...
     
  8. jhkimblue

    jhkimblue

    Joined:
    Mar 27, 2015
    Posts:
    14
    if you care about performance, and if you build a enough complex ui, 5.2.x is not a option for you.
    there was a huge performance regression since 5.2.x. so give it a shot with 5.1.3 or 5.1.4, that will reduce process time magically.
     
    aer0ace likes this.
  9. henkjan

    henkjan

    Joined:
    Aug 1, 2013
    Posts:
    146
    If you asign the right shaders to the text and image assets the performance regression will probable be gone. U could try these: http://forum.unity3d.com/threads/wh...p-work-in-ui-default-shader-of-newgui.364134/
     
  10. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    One scroll list with 5 items, another with ten.

    Custom shaders is asking a bit much! Doesn't the UI just use the same sprite shaders? That thread suggests clipping in shader. Makes you wonder why Unity didn't just copy NGUI's way of doing things. Maybe they wanted the flexibility of shaders per item? Overkill for a UI system IMO which first and foremost should be simple to use and fast so it doesn't impact the game.
     
  11. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    So Unity's had an update and the UI's as slow as before. Importantly it actually makes the tablet sluggish, with the system animations running at a dire framerate just as the game interface does. The above gave the impression Unity accidentally broke something with 5.2 and an update would fix it. Have Unity got no interest in working on this area? Isn't everyone else affected by impossibly slow UIs?
     
  12. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    I run a project with a bunch of uGUI stuff. 80 drawcalls was slowing things down way to much on Android. Optimizing it down to near 30-40 made it run smooth.
    Is there any particular reason, why you aren't using masks? Are you showing the entire UI all the time or are you hiding some of your elements most of the time? Using Canvas Group and setting the alpha to 0, when elements are out of view will stop the renderer on those items.
    Is there a chance you could be more specific as to what your setup is like? It's hard to know why it should run slow, not being able to see your project :)
     
  13. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    At the moment I haven't disabled any hidden panels. So in a scrollview of 3 full-screen pages, all three are active. Over the top is a character designer. Altogether there's 99 drawcalls. If I disable the off-screen panels, there's still over 50 though just for the character designer. Yet all the graphics are from the same texture sheet. It's as if the Unity UI creates a new DC for every element to something with zero batching or optimisation. As I say, NGUI does all drawing in 4 batches IIRC no matter how complicated the UI.

    Most importantly, I can't find any info on what optimisations can be made, leading to this thread and my current belief that there aren't any. The excessive number of DCs is just how Unity handles UI rendering.
     
  14. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    Maybe you should test the drawcalls and your texture sheet in an empty scene.
    I had 12 sprites, giving me 12 drawcalls. Put them on 2 atlas and it removed 10 drawcalls.
    It doesnt sound like your sprites are taken from the same atlas/sheet. Do you have a lot of panels with image components that you dont use?
    Atlas along with Canvas Group alpha, mask and/or hide elements did loads for my speed and drawcalls. It went from unuseable to smooth.
    But again, it's very hard to give you any detailed info without seeing an image of the scene and/or the hierarchy or similar.
    The profiler could help you locate the drawcalls, if I remember correctly as well.
     
  15. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Okay, after some experimentation the main problem seems to be Unity drawing disabled and off screen UIs. Removing unseen items reduces DCs to <30. Still terribly inefficient versus the competition though!
     
  16. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    If you have offscreen UI, have you tried to set a mask and see if that helps (I'm unsure whether I have tested it myself actually)
    Also, Canvas Group alpha is also way to "remove" the drawcalls on unseen items.

    Unity has made a bunch of UI changes with each version (including patches). I dont know which one you are working with, but upgrading/downgrading to certain numbers seems to help with performance and which things that help increase performance.
     
  17. Papatriz

    Papatriz

    Joined:
    Jan 7, 2014
    Posts:
    14
    We faced same problem with UGUI. Scrollview with 30 elements (list of achievments) runs terrible on IPad 3.
    We tried to remove all things step by step to find where problem is: mask, layout groups, stretch, best fit option for text, and texts itselves - nothing helps. We've got 56 fps after removing all, but scrolling still isn't smooth. There are spikes in profiler for Canvas.RenderOverlays -> WaitingForJob (biggest time) -> Canvas.PrepareBatches.
    Unity 5.3
    We couldn't find any solution, so we decide to use NGUI again.