Search Unity

Performances : Layouts usage

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by Sbizz, Jul 6, 2015.

  1. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Hey,

    I was wondering if it was a good idea to use "often" Layouts component (Layout Element, Layout Horizontal & Layout Vertical) when we build our UI ?

    I use it ALL the time, because it is easier to have everything placed where it has to be, automatically. But when I use the Profiler to see what components take a long time to do whatever it has to do, ScrollRect.LateUpdate (more precisely LayoutRebuilder.UnityEngine.UI.ICanvasElement.Rebuild) takes a lot of time when I active my windows.

    For example, I have a panel that you can Active (or not) when you press a button. In this panel, there are 324 Layout Element, 74 Layout Vertical and 130 Layout Horizontal*. And here is the Profiler when the user actives the panel :

    LayoutElements.jpg

    * checked with this script :

    Code (CSharp):
    1.     void OnEnable() {
    2.         CountNbLayouts();
    3.     }
    4.  
    5.     void CountNbLayouts() {
    6.         LayoutElement[] layouts = transform.GetComponentsInChildren<LayoutElement>();
    7.         VerticalLayoutGroup[] layoutsV = transform.GetComponentsInChildren<VerticalLayoutGroup>();
    8.         HorizontalLayoutGroup[] layoutsH = transform.GetComponentsInChildren<HorizontalLayoutGroup>();
    9.  
    10.         Debug.Log("L: " + layouts.Length + ", V: " + layoutsV.Length + ", H: " + layoutsH.Length);
    11.     }
    So.. ?

    Thanks :B
    Sbizz.
     
  2. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    312
    I had a ScrollRect with lots of static contents instantiated from prefabs that didn't change size after creation, so I had a script disable all the layout elements after they're initially positioned. It helped some, since all the scrollable items didn't have to recalculate the layouts every frame anymore.
     
    eses, Multithreaded_Games and blizzy like this.
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    I use a decent number of kissLayout's, like in the Windows Desktop WebPlayer Demo, but thats for kissUI. Doesnt slow it down too much.
     
  4. Mikea15

    Mikea15

    Joined:
    Sep 20, 2012
    Posts:
    93
    I'm having the exact same problem. This reduced my framerate on mobile devices from 60 to 30. its still good, but its unacceptable.

    Has anyone found a way to fix this?
     
  5. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    DUDE... I had to post here simply to let you know how amazing of a suggestion this was. This literally reduced my 23ms spikes to somewhere in the neighborhood of 8ms. I love you.
     
unityunity