Search Unity

Bad Performance in Unity 5 caused by UI?

Discussion in 'iOS and tvOS' started by DennG, Apr 14, 2015.

  1. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    Hello,

    I'm experiencing a really slow startup on my iPhone 4S test device and low fps.
    Also my iPad Air is struggling a little bit at the beginning, but running smooth ingame.

    Here is a screenshot of the first frame in the profiler (iPhone 4S):


    One of the frame in the Main Menu:



    The whole game is in one scene and there are hundreds of UI Objects on Worldspace canvas.
    Are non-visible Elements occluded somehow or are they rendered all even if not on camera?



    All the planets/levels are worldspace UI and the camera is running on a path.
    50 levels on one huge canvas... is this even a good pratice?

    Also the Startup is a little bit weird.. first its 2-3 seconds black, then the Splash Screen comes up for another 3-4 seconds, but in the background the game already started. Why is that?

    Please help me to improve the performance on this scene.

    Best regards
    Dennis


    ps. The hit on performance on android devices is not as big as on iOS devices... that's strange
     
    Last edited: Apr 15, 2015
  2. di-lshod

    di-lshod

    Joined:
    Jan 15, 2013
    Posts:
    10
    Try disabling pixel perfect option for all canvases.
     
  3. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Just curious, but what does this exactly do and how you know disabling improves performance?
     
  4. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    Yea, I would like to know that too.
     
  5. di-lshod

    di-lshod

    Joined:
    Jan 15, 2013
    Posts:
    10
    I had a similar problem, low fps when you move something on ui. As i remember, if pixel perfect is enabled, when you move parent element, ugui recalculates positions (and sizes) for all descendants to make them pixel perfect.
     
  6. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    I solved my problem by writing my own "UI Culling".
    Off-screen UI elements are not rendered anymore, which gave me a huge performance boost.
    It's running on 60 fps now.

    I also disabled pixel perfect just to be safe.
    Thank you guys.

    Special thanks to @Marceta for pointing out the fact that even off-screen UI elements are rendered.
     
    Marceta likes this.
  7. Toolism

    Toolism

    Joined:
    Apr 10, 2014
    Posts:
    12
    Can you share some more detail in terms of how you wrote the culling? Do you SetEnable(false) the elements? or are you disabling the renderers? Do tell:)
     
  8. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    I've written a coroutine with a endless loop inside and a WaitForSeconds(0.1f) at the end of this loop (I call this SlowUpdate).
    It's looping over all UI GameObjects that I put in an array before. For each GameObject it's calculating the Vector3.Distance to the camera.
    When the distance is bigger than a certain threshold it's doing SetActive(false). When it's less then vice versa.
    There might be a better solution, but that's working great for me.

    If you got any questions on this don't hesitate to ask.