Search code examples
androidunity-game-enginegoogle-cardboard

UI/Canvas appears in front of objects, even though it's set to World Space


In my Google Cardboard project, I have several canvases attached to walls in a room. These canvases have buttons the player can interact with. I set each canvas to World Space, but for some reason, the buttons are rendering in front of objects that should appear in front of the buttons.

update1: The UI appears behind the cube in the game and scene windows when not running. It's only when I hit play that the image appears in front of the cube. I am adding images to the UI button programatically, but the problem happens even if I add images only using the editor.

update2: If I disable the cardboard elements in my scene (i.e. use a standard fps camera setup), I do not get the issue.

Picture below: Checkerboard is UI. Gray block is 3D block. I want UI behind the block, on the wall.

checkerboard should appear behind the block

canvas object

enter image description here


Solution

  • Someone on answers.unity3D made this suggestions:

    The problem may come from the shader used by the UI element with a ZTest value set to Off or the Queue tag of the UI element's shader is "higher" than the tag of the cube's shader

    Turns out, and this is apparent in the 3rd screenshot, my UI buttons did not have a material. Once I provided one, I used one that used a standard UI shader (I initially tried unlit, but that made them disappear).

    I guess there are still some issues with shaders and google cardboard. Thanks guys