Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Is there a Z-order of UI elements

Discussion in 'UI Toolkit' started by mfatihbarut, Jan 14, 2021.

  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,061
    Hi,
    I couldn't change z order of UI elements (image button etc.)
    Is there any option for it?
    Thank you.
     
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    unity_mWV6NmUpAKbbsA likes this.
  3. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,061
  4. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    812
  5. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    You simply call BringToFront() on the element that you want to be drawn on top.

    For example if you have a container and you want the first child to be on top.
    Code (CSharp):
    1. var container = new VisualElement();
    2.  
    3. //...
    4.  
    5. var firstChild = container[0];
    6. firstChild.BringToFront(); // firstChild will now be the last children of the container
     
  6. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,061