Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

VisualElement sort order

Discussion in 'UI Toolkit' started by Romeno, May 31, 2021.

  1. Romeno

    Romeno

    Joined:
    Jun 24, 2013
    Posts:
    34
    Hello, suppose I have UI made in UI Toolkit. How do I bring an element to the front?

    Suppose I'm making a FTUE (first-time user experience) and I want to highlight an element and make it clickable while darkening anything else. I would approach this by adding a dark overlay that blocks raycasts and changing some "sort order" of an element to render on top of the overlay. How do I change that "sort order"? Or how would you do that?
     
  2. YuuHao

    YuuHao

    Joined:
    Apr 14, 2020
    Posts:
    48
    Some methods in VisualElement may be useful.
    Code (CSharp):
    1. public void Sort(Comparison<VisualElement> comp)
    2. public void BringToFront()
    3. public void SendToBack()
    4. public void PlaceBehind(VisualElement sibling)
    5. public void PlaceInFront(VisualElement sibling)
     
    achimmihca likes this.
  3. Romeno

    Romeno

    Joined:
    Jun 24, 2013
    Posts:
    34
    Thanks for the hint. I looked thru the code briefly and they appear to move the object down/up hierarchy. Does that mean the VisualElement also change its position etc (if controls )?
     
  4. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    235
    That depends on your layout : if your control is inside a classic flex container, with other UI elements/controls, yes it will change position.

    Reminder : the z-order of the UI elements is dictated by the hierarchy.

    I had a use case where I needed to display a UI row element on top of all the other rows, while dragging the row.
    I eventually added a ghost row, using absolute positioning, on top of all the rows, which would duplicate the state of the row to drag. Maybe this trick will help you find a solution for your use case !
     
  5. Romeno

    Romeno

    Joined:
    Jun 24, 2013
    Posts:
    34
    Yeah, I thought about that too as a last resort... Doesn't UIToolkit provide the ability to change z-index? Realy. I looked at UIElements like 2 years ago? And there were no ability to do that at that time. I thought ok it is still raw. It should not be used yet...

    And now after 2 years there is still no this basic feature?
     
  6. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    757