I’m using plugin GUIAnimator asset to animate my UI elements. In my scene I have some pop up dialogs that active in the scene but the plugin set the initial scale value of all UI elements to 0. I’m affraid that enabling all the unused UI elements would affect my performance. So I want to ask if I have unused active UI elements with 0 scale would affect my performance ? Please enlighten me.
No, it’s not the same in performance.
So it’s bad to have unused active UI elements with 0 scale ?
Is it bad for your project?
I have no idea. That’s why I’m asking which is better between those two as I mentioned above in performance?
Use profiler so you know.
My hypothesis is that setting scale to 0 is worse on performance. After all, the object is still in the scene, just too small to be seen.
Yep, it’s one of those problems that waste forum time and vaguely insult elitist devs
not really a problem.
Last I profiled it putting out of use UI onto a layer that wasn’t rendered by the camera performed best. However that was well over a year ago. I would strongly suggest profiling it with you specific game.
Setting scale to 0 is also triggering a few red alerts in my head. If you are doing this simply to hide stuff, then I’d say you’re better off setting alpha to 0, or simply disable the gameobject (or just the renderers if you want to be careful to not disrupt coroutines).
Unless the code is very well written, 0 scale can be a good source of divide-by-zero errors.
As far as I know, scaling the object to zero does not disable the object - it just gets hidden on screen. There are some major differences between setting scale to zero and disable the objects:
-
Disable the object will also disable its components and the update loops so none would get updated, it can save your performance significantly.
-
If you have colliders, it might behave weirdly
-
Disabled objects will not be pushed to render queue, so you have batch count, rendering time, etc.
Also, as @BlackPete have pointed out, it can be a good source for divide-by-zeroes errors. However, setting alpha to zero is actually still as bad as setting scale to zero, since it still inherit the problems above. I would suggest to just use SetActive if possible, unless you really flip the object on/off every frame (in that case, set its position outside the camera frustum whenever you need to “turn off” the object)
Then I came into conclusion that GUIAnimator asset is not well optimized because they hiding those elements by setting the scale to 0. The profiler seems just normal in the editor but when I build it to android device, I got slight time of delay when I hold the virtual button to move my character. Sometimes profiler is useless especially for mobile build.
You can attach the profiler to your build on mobile if you set it to development. At least for Android. I think it’s true for iOS also, but I might be wrong there as I don’t do those builds that often.
Can you share a link to the asset you’re using?