Search Unity

Question Rendering order on UI layer

Discussion in 'General Graphics' started by PenProd, Mar 17, 2023.

  1. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    First off, it could very well be that I'm using the UI layer incorrectly. This is my first project/game in Unity so I'm still learning.

    What I'm doing is actually using a 3D object on the UI layer; a code lock consisting of a housing and three dials. The problem is that the different parts are rendered incorrectly. It first renders the housing, then on top of that the dials.

    This is how it should look:

    upload_2023-3-17_11-20-5.png

    But this is how it's rendered:

    upload_2023-3-17_11-21-25.png

    It looks even weirder from the side:

    upload_2023-3-17_11-24-33.png

    I tried changing the order of the parts in the hierarchy, but that made no difference. I read somewhere that objects are rendered from back to front, but if I move the housing in front of the dials, it doesn't change the rendering order.

    But, it gets even weirder still. Some normal game objects (on the default layer) are rendered on top of the UI. Like this carpet:

    upload_2023-3-17_11-37-45.png

    There's nothing special about the carpet, it's just a plane.

    Soooo, help please?
     
  2. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171
    Ok, I just found out what is causing the problem. But still don't know how to solve it.

    Earlier, I had created RenderObjects because I wanted the UI to always render on top of everything. Before that, if I was standing close to a wall and called up the UI, it was (partially) rendered behind the wall and therefor invisible (obscured by the wall). So in the shader, I created these two RenderObjects:

    upload_2023-3-17_12-42-51.png

    As you can see, I changed the "Depth" to never write depth to the screen (causing UI object to never get clipped). Unfortunately, this also causes all the above render problems.

    In normal circumstances, you would use a second camera for UI elements and stack the cameras. However, since I'm developing this game for Quest VR headsets, the performance hit on these devices is huge when you use stacked cameras. Which is the reason I did it the way I did.

    But I still have no idea how to solve this.
     
  3. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    171