UI stays behind game objects

Hi!

Currently I have a problem with my UI. Due to some warping that is being done with the camera (to fit the rendering nicely onto a projector while remaining 16:10) I have to use the “Screen Space - Camera” option on my UI. This has however caused the UI to stay behind my game objects. This can be seen on this image for example:
78072-dsc-0002.jpg
The settings on the UI are as follows:

  • The main camera is set to the correct
    camera
  • The plane distance is set to 0.31,
    the cameras near clipping plane is
    set to 0.3
  • Sorting layer is set to ‘Default’
  • Order in layer is set to ‘0’
  • Rect Transform scale is set to
    0.0002443…

I’ve tried many different things and the only thing that worked so far was changing the rendering mode from ‘Forward’ to ‘Deferred’, but this caused a whole lot of game objects to be rendered bad.

Does anyone know how I might be able to solve this issue?

if you are using “Screen Space - Camera” in canvas then decrease the value of “Plane Distance” in canvas.

If you really have to use screen space camera instead of screen space overlay and your camera is that close to objects that the UI will clip through. I think you don’t have that many options…

These are the ones I can think of:

  1. Set the plane distance as low as possible (Think you already did that)
  2. Make sure the UI component don’t have their z position set (to anything above 0, as this will move them further away from the camera, higher chance they will clip through the objects you are looking at)
  3. ignore point 1 and 2 and use another camera used only for the UI You can make this new camera a child of your existing main camera for instance. Make sure its culling mask is set to UI, your other cameras ignore UI and then play with the depth of your new camera (Make sure its value is higher then the depth of your main camera) And ofcourse make sure you set this camera as render target of your canvas. Also, set the new camera clear flags to depth only :stuck_out_tongue:

I believe setting the sorting layer and order in layer has no effect as these values are ignored by 3D objects. If you are not using 3D gameobjects but 2D ones instead (Sprite Renderer instead of Mesh Renderer), they should work I believe :wink:

Did you trt ordering the layer of the gameobject?78075-screenshot-1.jpg
Try setting the value to negative.

Adding a new sorting layer and adding my Canvas to it did the trick for me.

I had same Problem. Increasing Depth in camera settings, fixed my issue.

Where they in the same sorting layer?
It happened to me and I had the canvas in default and the objects in another one…