neither set visible to false nor opacity to zero improves performance

When I toggle my root VisualElement by visible or opacity, doesn’t saves cpu time.

Btw, I can still see draw commands for invisible element in Frame Debugger.

Is there a workaround for optimizing ui tree by hide some element except display:none?

Hi,

You can use the display: none style in USS or element.style.display = DisplayStyle.None in C# to that effect. The element will be skipped during layout and other operations like event picking and rendering.

I am checking with the team about still seeing the element when opacity is zero or when visible is false.

Hi, antoine-unity. Thanks for your reply.

I am seeking for a way to manually prune unnecessary branch in ui tree to optimize runtime performance. For instance, a heavy element is covered by others or moved out of canvas can be “prune”.

Sorry for my poor Engine. When opacity is zero or when visible is false, the element does disappear as expected.

However, what prevent me from going on is:

  • Setting the visible, the GPU time decrease, but the children with visiblility to true can still be seen.
  • Setting the opacity, have no benefit on runtime at all, and we can still see the draw commands for the zero-opacity elements in Frame Debugger Window.

“display:none” is neither a alternative for me, because I have to preserve the bound of elements for my optimizing logic.

Yes this is the expected behaviour, however there is a subtle difference between setting visibility = true and not assigning the property at all. This is because visibility is just an alias for style.visibility, which has the ability to be unset, in which case the value of the first parent setting visibility wins. However, if a child has a value set, it will override the one from the parent.

Hopefully this information will help with your problem.

This is expected too, opacity is optimized for animation and not meant to hide elements as a cost saving measure.