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

Struggling with UI Performance

Discussion in 'UGUI & TextMesh Pro' started by riot9, Sep 1, 2015.

  1. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Hi everyone. Thanks in advance for looking at this. Disclaimer: I am totally an amateur, so please forgive me if I mess up some terms.

    I've been working on a text based adventure for quite a while now. In general have been really happy with the results I've had with Unity until I started testing on mobile devices.

    From the image you can see I've got a scrollrect that has a vertical layout group that has narrative, conversation, and action confirmation slider elements in it. The conversation elements are horizontal layout groups with an image and text.

    I can load 15 or so of these conversation elements into a scrollrect and my FPS will drop from 60 to 40, but scrolling is generally okay. What does kill my framerate though is an autotype script on each of the conversation elements. It types them out one letter at a time.

    It works fine with only a few visible, frames will hover in the 50s, but once I've typed out 6 or 7 (on a snapdragon 400 device) my frames drop below 20. Once the whole page of conversation elements have typed out, scrolling is okay and FPS go back up to 40.
    I thought it must be my coroutine, but I rebuilt it with a state engine instead and it had the same problem. After days of troubleshooting, I don't think it's so much the autotype script by itself, but a combination of the general load of my UI elements plus anything else taxing the CPU.

    I've been trying all of the suggestions I can find.
    http://forum.unity3d.com/threads/unity-ui-best-practices.313416/ offered a lot of leads, but nothing has really helped. I tried using canvases to disable items not on the screen. It certainly lowered my tris, but my batches nearly doubled (still not sure if I did something wrong there). I tried converting everything to a bitmap font, but that didn't help either. I'm not using pixel perfect.

    I tried deactivating UI elements on screen (my buttons, scrollbar, framecount, etc), anything to get my batches lower. But even with lowered batches (I can get them down to about 15) my framerate is terrible.

    Unfortunately I'm using the community edition, so I don't have access to any performance monitoring tools.

    Would TextMesh give me better performance? Seems like I'd give up on a lot of the conveniences of UI to move to TextMesh, but I'm pretty discouraged. I've also seen talk of 5.2 being performance focused, could that do the trick? Or are there any plugins that might help?

    Sorry for the rambling, seemingly disorganized question. After a week of this I'm a bit discouraged and worried that Unity might not be the right tool for what I'm trying to accomplish.

    Any advice? Words of encouragement? Anyone to talk me back from the metaphorical edge?

    Thanks
     

    Attached Files:

  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use the profiler to see where the bottleneck is. There's no difference in engine features between the personal and pro licenses.

    --Eric
     
  3. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    *blink*

    So that's awesome. Thanks! Now to figure out what this actually means. And also to get it working on a device other than my PC.

    Thanks again, I really appreciate it.
     
  4. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    So the profiler confirmed my suspicions. The script is not affecting performance at all. When my frames get really low almost all CPU time is spent on "Overhead" which is labeled as other, and Graphics.PresentAndSync, which is labeled as rendering. Under Graphics.PresentAndSync, Device.Present looks like the cause.

    Overhead accounts for about 60-70%, and rendering takes up the rest. Does this offer any clues?
    Or should I maybe strip my prefabs down to bare bones to see if anything changes?
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    This is normally editor overhead and other things. Build a standalone player, disable vsync, and attach the profiler to the standalone player. It's the only real way to measure performance.
     
  6. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks for the reply Tim!

    I should have been more specific. When I ran it attached to the editor I got huge spikes on vsync and WaitForFPS (or something like that). A quick search led me to believe exactly what you just said.

    So I did build it on a standalone player and ran it on a Nexus 7 (2nd gen). That's where I ran into the Overhead and Rendering problems. Vsync didn't seem to show up at all as a problem on the Nexus.

    I'm relieved that I can't even really see my script on the graph unless I turn all the other categories off, though. Seems like the script is the least of my worries.

    But I am still sort of in the same place I was before, wondering why on earth a total of around 50 GameObjects, and roughly 200 components total in the scene has such bad framerate.

    It looks like my batches stay about the same almost all the way through, between 14 and 18. There's a ramp up in Tris, which is understandable. It never goes over 4.5k though.

    If anyone has any ideas I'm certainly open. I think my next move is to try to strip down all my prefabs. Maybe try doing my layout manually in code rather than using layout elements.

    Thanks again Tim, and anyone else looking at this.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Always turn off vsync, if possible (not possible on iOS).

    --Eric
     
  8. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks again Eric. I just turned it off. I think it may have had a slight impact. I think I'll just have to pick my scene apart bit by bit and figure out where my problems are.

    Thanks everyone, I appreciate it.