- Home /
From an optimization point of view, what optimizes different resources better? Activating/Deactivating UI elements or hiding and showing UI elements using CanvasGroup's alpha?
What is the most optimal way to conserve resources when dealing with a UI-heavy application? Should unshown UI elements be deactivated or should they just be hidden by a CanvasGroup.alpha
?
Answer by TonyLi · Apr 28, 2017 at 06:45 PM
Do you want to optimize CPU cycles or memory?
Neither deactivating UI elements nor setting CanvasGroup.alpha to 0 will free up much memory. To do that, you'll want to actually unload the UI elements from the scene.
Also, be aware that (re)activating a UI element will cause it to recalculate layout, as well as meshes for Text components in all children, which can cause a stutter on that frame depending on the complexity of the UI. When optimizing for performance, this is worth considering.
Another alternative to setting a CanvasGroup's alpha to 0 is to disable the CanvasRenderer. Both of these techniques keep the layout in memory so it won't have to recalculate. But they also both keep the UI elements accessible to the GraphicRaycaster for selection by the pointer, and any scripts running on the UI elements will continue to run, unlike deactivating the GameObjects.
The Optimizing UI Controls and Other UI Optimization Techniques And Tips pages contain good information about this subject.
Answer by laurentlavigne · Apr 28, 2017 at 05:49 PM
alpha=0 gets culled out of the display list but SetActive(false) or enabled=false gets culled out of the update loop, which is even less work.
Your answer
Follow this Question
Related Questions
Access text label inside a button - Unity 5.1.4 1 Answer
Android performance hit on changing Button.Interactable 1 Answer
Canvas is hiding my 3D model, can I place the model in front of the canvas? 1 Answer
How to make my code stop running, until the player responses to a prompt 1 Answer
UNet and player UI 1 Answer