Search Unity

UI Image sorting layer?

Discussion in 'UGUI & TextMesh Pro' started by spritesobhan, May 14, 2017.

  1. spritesobhan

    spritesobhan

    Joined:
    Mar 28, 2017
    Posts:
    73
    I have two UI Images, one is a white box, one is a sprite. However, the white box blocks the whole potion sprite, since there is no such thing as sorting layer in gui.

    I even tried moving the Z position of the white box. it makes no difference.
     
  2. andymakesthings

    andymakesthings

    Joined:
    Sep 4, 2015
    Posts:
    18
    On the image component you can uncheck "block raycasts" then you can click through it.
     
  3. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    yes, there is sorting layers for canvas... so you could either:

    add two canvas, each with a different layer or
    order the object differently in your hierarchy... it's bottom/up > back/front
     
  4. gamedevgarage

    gamedevgarage

    Joined:
    Apr 21, 2018
    Posts:
    6
    The most important function of a sorting layer is that you can override render order without changing the hierarchy. I have a menu item list with image components on them and want to change their render order without changing the hierarchi.
     
    Absolute0Unit likes this.
  5. itsgatsu

    itsgatsu

    Joined:
    Mar 30, 2021
    Posts:
    1
    you add the canvas component to the same object as your image. Then change the sorting order of the added canvas. Basically you are using the canvas component just to add sorting functionality, but it will change nothing else
     
  6. antidrop

    antidrop

    Joined:
    Apr 14, 2021
    Posts:
    1
    Thank you very much, it changed my life !
     
  7. hsgaminators

    hsgaminators

    Joined:
    Dec 19, 2021
    Posts:
    5
    You're a legend.
     
  8. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    Yes... Yes he is...
     
  9. Mindtoast451

    Mindtoast451

    Joined:
    Aug 2, 2013
    Posts:
    20
    Priceless bit of wisdom!
     
  10. unity_6C82258DF4F967069335

    unity_6C82258DF4F967069335

    Joined:
    Sep 23, 2022
    Posts:
    11
    there are 3 buttons if I press one button it will scroll to that specific content. Or if I scroll the content to next content, it will automatically switch the button I want this function in my shop/Inventory system in canvas Unity
     
  11. nhannguyendev0

    nhannguyendev0

    Joined:
    Sep 25, 2022
    Posts:
    1
    Thanks guys.
     
  12. Smams68

    Smams68

    Joined:
    May 28, 2023
    Posts:
    15
    jesus christ. thank you
     
  13. Gamer98898

    Gamer98898

    Joined:
    Nov 18, 2017
    Posts:
    12
    Thanks,
    this solution works .
     
  14. Smams68

    Smams68

    Joined:
    May 28, 2023
    Posts:
    15
    this is my friend in Jesus, right here.
     
  15. Smams68

    Smams68

    Joined:
    May 28, 2023
    Posts:
    15
    oh it's you again
     
  16. Batracien333

    Batracien333

    Joined:
    Jul 12, 2022
    Posts:
    1
    Still many years after your answer, this simple piece of information that I was unaware of really saved me so much time and avoided me some pretty sketchy hierarchical djenga that I was starting to try. Right after seeing your comment, tried to check that in unity and seen some little box called "Override Sorting" that I haven't noticed before, it's like a bonus layer order that I didn't knew existed. You don't have any idea how this really super simple thing that I was missing avoided so many complications in my actual project, I mean it saved me days and days, litterally.

    So, thank you again. That may even be my first comment on here after all those years developping with Unity, just to tell how much this small bit of information helped me greatly on a crucial thing. It will changes so much things.

    Where ever you are, have a nice day dear other human being :)
     
    bravophantom likes this.
  17. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    711
    This can also be achieved by dynamically setting new\lower\higher sibling indexes on the transforms (assuming they have the same parent)

    There are a handful of methods (set\set first\set last\get) that will help, i.e.

    https://docs.unity3d.com/ScriptReference/Transform.SetSiblingIndex.html

    It's simpler (and potentially a little more efficient) than working with multiple canvases imho.
     
    Last edited: Aug 8, 2023
  18. KrimKram69

    KrimKram69

    Joined:
    Aug 17, 2023
    Posts:
    1
    i know it's late, but I simply changed the order of the UI Elements in the Hierarchy and it worked
     
  19. AndreaGalet

    AndreaGalet

    Joined:
    May 21, 2020
    Posts:
    97
    Yes this will work but not for my case in which i have elements that are sorted from an horizontal layer and if i change the hierarchy position it will change the position also in the list, it will not maintain the same position on the ui. Adding another canvas specifically resolve the main issue of this thread.
     
  20. quiphop

    quiphop

    Joined:
    Jan 26, 2020
    Posts:
    1
    You saved my week, thank you :cool:.