Search Unity

Question New Usage Hints clarification

Discussion in 'UI Toolkit' started by Midiphony-panda, Nov 29, 2021.

  1. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Hello ! :)

    I discovered the newer Usage Hints in Unity 2021.2 and would have liked a little clarification on these.
    https://docs.unity3d.com/2021.2/Documentation/ScriptReference/UIElements.UsageHints.html

    The documentation is good for programmers but I'd like to give simpler explanation to our UI designers.

    There are cases where multiple usage hints would suit (e.g. an element which often changes its position and its color).

    Is there some kind of priorization over the usage hints ? How should we mark VisualElements on intersecting use cases ?

    Thanks !
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    377
    Hi,

    Basically these are used to guide some internal optimizations. They are flags so you can define multiple usage hints. So if the position and the color change, you can set both DynamicTranform and DynamicColor.

    DynamicTransform* shoud be used on a VisualElement whose transform changes from time to time. The vertices will be transformed on GPU. If it's not set, we'll transform them on the CPU when there's a change.

    GroupTransform* should be used on a VisualElement whose transform changes often AND under which many children have DynamicTransform set. If you think of Shader Graph, the individual nodes have DynamicTransform set on them, but the "panner/zoomer" ancestor has GroupTransform set on it, so that when we pan/zoom, we don't have to update hundreds of dynamic transforms.

    MaskContainer is only relevant when nested masking is used (i.e. nested cases where you have overflow=hidden with rounded corners/svg background). It allows to reduce the number of stencil state changes. It should be used on a VisualElement that contains multiple descendants that are nested masks. See the attached picture. Basically it's a tool that allows to take advantage of the fact that we can have free consecutive mask push/pop.

    DynamicColor allows colors (border, background etc) to be fetched from a buffer on the GPU, so that when it does change, we don't have to re-tessellate the geometry or update it from the CPU.

    *DynamicTransform and GroupTransform should not be used both at the same time on a single VisualElement.
     

    Attached Files:

    Last edited: Nov 30, 2021
    Timboc and Midiphony-panda like this.
  3. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Thanks ! :)

    Is there any interest in setting both DynamicTransform and DynamicColor on the same element ?
    targetElement.usageHints = UsageHints.DynamicTransform | UsageHints.DynamicColor;


    If so, can we (or will we be able to) set multiple flags from the Builder ?
     
  4. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    377
    Yes, if both the color and the transform are changing every so often, you can use both hints. The hints have been added to the Builder some while ago.

    upload_2021-11-29_9-34-42.png
     
    Midiphony-panda likes this.
  5. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Thanks for the reactivity and the clarifications ^^

    For others, you can indeed set multiple flags on 2022.1 alpha but it's not possible on the latest Unity 2021.2(.4) version.
     
    Last edited: Nov 29, 2021