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. Dismiss Notice

Question How can I set up different render layers for UI components

Discussion in 'Editor & General Support' started by DripSta, Jul 26, 2020.

  1. DripSta

    DripSta

    Joined:
    Apr 20, 2020
    Posts:
    56
    I would like certain UI components to be drawn on top of others in order to make them noticeable to the player
    Cause when I move some UI components via script, they always are rendered behind other UI components. Is there a way I can make it so that I can selected which UI components render on top of one another?
    Like how it is done in the 2D world with render layers, can UI components also use render layers?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Two approaches:
    • The order they appear in the hierarchy affects their sort order. Lower down in the hierarchy means on top of objects above it, if the objects are in the same canvas.
    • If you have multiple canvases, you can set the Sort Order of the canvas it affect which canvases are draw on or under other canvases.
     
  3. DripSta

    DripSta

    Joined:
    Apr 20, 2020
    Posts:
    56
    I tried that but see the problem is that the script causes some UI elements to float and fly towards a score board and the UI elements move randomly because they are set up to represent a board and, for example, tile one may fly to the score board or tile 100 so you see, sorting them in the hierarchy doesn't really help because they move at random
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Then how do you want to sort them? If you have 100 things all floating around screen, and some overlap others, you'll need to decide which should be on top. Which do you prefer be on top? Are you saying that at some point, an arbitrary tile will float to the score board, at which point it should be on top of all other tiles? If so, one easy approach would be to deparent then reparent that image, which would put it at the bottom of the list in the hierarchy, and put it visually above another else in that directory.
     
    DripSta likes this.
  5. DripSta

    DripSta

    Joined:
    Apr 20, 2020
    Posts:
    56
    Thank you so much. That will work:)