I’ve got a little UI test scene - a little performance test with 64 items in a ScrollRect, each item is an instance of a prefab, containing two UI.Image sprites (one regular, one sliced) and a very simple script to rotate one of these sprites.
When rendering and scrolling normally, the profiler is looking good (~1ms CPU in the editor)
But if I disable and then re-enable the contents of the scrollrect (just by enabling/disabling the parent node manually in the editor, for now), I’m seeing a 10-15ms performance spike. (And obviously that sort of spike is going to be bad news on a significantly slower mobile device). The spike is only present on enabling the objects, not when disabling them.
The time is apparently spent in ‘Canvas.SendWillRenderCanvases’. Is this normal/expected?
I was hoping that in uGUI, enabling/disabling elements would be more-or-less free? (The cost of enabling/disabling large groups of UI elements has been a problem that we’ve had when using NGUI, but I was hoping that with parts of uGUI being native, and no colliders being involved, that it would be fast/near-free?)
Total uneducated guess, but try disabling/enabling from a script instead of using the editor. I know that sometimes doing stuff through the editor has overheads you don’t usually get.
i have a similar setup in my project, but the performance spike is worse: i have 9 scrollrects each with 30-33 similar (a button and some text) item instances in a panel that i enable/disable from script, causing a very noticeable 2-3 second (!) hiccup on re-enabling.
I just noticed this issue myself while testing on Windows Phone.
In my scene I have several different menu screens that can be switched between, and I use a simple script to fade them in & out using a CanvasGroup. This works well, but if I add some extra code in to deactivate the GO when the alpha reaches 0 then I get lag spikes whenever I switch menus. Here’s a profiler shot of the spikes on my Lumia 520:
Simply fading in & out one menu screen. As you can see, the first elevated region is where it fades in, and the second is where it fades out. The performance impact here isn’t too bad.
Exact same thing, but activating & deactivating the GO when the CanvasGroup’s opacity reaches 0. As you can see, enabling the GO has a massive impact, and the 2nd spike is where I begin fading out, and the last spike is where it gets disabled. Also note: this menu has been ‘warmed up’ before taking these pictures.
As you can see, there’s no special OnEnable code on my end causing any of these spikes. I’m deliberately testing on the Lumia 520 because it’s a slow device, but these spikes are too severe for me to release it like this, and keeping all the menus active-but-invisible all the time takes up too much performance.
We’ve experience the same issues. One thing you can try is to just set the Canvas component enabled = false. There is not as much as a spike, and it does stop the Canvas from being rendered. The objects are still active, but the performance impact of having invisible active objects is usually minimal (unless you’re doing alot of Update calls, etc)
@Darkcoder_1 We worked a bit on optimizing the Enabling/Disabling of UI elements. The spikes should be much smaller now. It should probably be out in the next Patch Release. There is still more work that can be done in this area and is something we will get back to for another optimization pass.
Good to hear someone is looking into this issue,
When you say patch release is this the one coming today hopefully Patch 4, or next week Patch 5?
Although we are due a point release soon I guess.
Still persists in Unity 5.0.1
I am having 6.21ms spikes when i enable panel gameobjects on my canvas, which causes freezes.
Is there a proper way to do this ?
There is a bypass by adding “canvas” component to every panel on a canvas and keep them enabled, but the still consume a lot of render time and memory, espesially when you have 20 panels on your canvas.
I’m using Unity 5.1.1 and enabling one single 50 x 50 UI Image is causing a massive spike in my game, so I’m wondering if anyone found a solution or alternative yet?
Hi. We’ve ran into the same issue and developed our own utility that both dynamically populates a scrollview and greatly increases performance. You can have any prefab, list of prefabs, prefabs with different heights. It’s highly customizable. It’s 5 bucks on asset store(see the video for comparisons): https://www.assetstore.unity3d.com/en/#!/content/58158
EDIT: happy to announce V2.0 is out, improved and with horizontal support: http://u3d.as/xXQ
If you’re seeing this issue and you use Advanced FPS Counter, try unchecking the Shadow and Outline effects. They were the cause of these spikes for us - everything works fine when the effects are disabled.