1
\$\begingroup\$

I'm using a canvas with screen space - camera because I needed a line renderer that could work for my UI.

However, I need that line to render behind Image elements on my canvas and I'm not seeing any way to accomplish that.

Every UI element on my canvas behaves like its z:90 and "order in layer": 0 but those aren't really configurable values for a UI object. My line renderer, if z:90, must have a layer order > 0, or a z value < 90. In both cases, it shows on top of my UI.

I essentially have a canvas with a background image, which must be behind everything else, a line renderer (used to connect "dots"), and circle-shaped Images which must be on top.

Here's my hierarchy:

Canvas
  |- Background (Panel, no image, color)
  |- GameBoard
       |- LineRenderer (Layer: default, order: 0)
       |- Circle Clone(1)
       |- Circle Clone(2)
       |- etc...

What's bizarre is that if I turned off (active=false) the Background object, and my LineRenderer is z:90, order: 0, it works fine. It appears behind my UI elements correctly. Yet if this object is active, my LineRenderer appears on top of of the elements, despite no z/order changes.

\$\endgroup\$
0
2
\$\begingroup\$

Instead of changing Z-position you can solve this problem by Using Rendering Order

You can determine in which order your objects are drawn using the Queue tag. A Shader decides which render queue its objects belong to, this way any Transparent shaders make sure they are drawn after all opaque objects and so on.

assign Sprites shader to your line renderer's material because It have Important tag as ZWrite.

Controls whether pixels from this object are written to the depth buffer (default is On). If you’re drawng solid objects, leave this on. If you’re drawing semitransparent effects, switch to ZWrite Off. For more details read below.

so if you have custom shader use Zwrite Off then set your own Rendering Order like this:

image

\$\endgroup\$
1
  • \$\begingroup\$ I was able to get it working with custom render order values set for materials based on the default sprite/text shaders. I'm quite surprised that drawing lines and shape primitives in the UI is so problematic in Unity. \$\endgroup\$
    – BotskoNet
    Mar 10 '18 at 16:10
0
\$\begingroup\$

To render a line behind a camera space canvas, the line will need to be behind the elements. By default, LineRenderer is set to 'use world space', so setting it's Z position will not affect the position of the line. You can check this by disabling '2D' on the top left of the scene view.

So either you can set the Z position of each vertex on the line to be behind the canvas, or you disable 'use world space' on your LineRenderer and move that. You can also set the plane distance of the canvas to be closer to your camera.

\$\endgroup\$
2
  • \$\begingroup\$ I've already been adjusting the vertices of the line in world-space coordinates but there's no way to put it between two canvas UI elements. The background must be behind the line renderer/line vertices and the circle objects must be in front. \$\endgroup\$
    – BotskoNet
    Mar 7 '18 at 15:18
  • \$\begingroup\$ @BotskoNet If You work in 2D environment you don't need to work in world space when you assign Material with Sprites shader \$\endgroup\$ Mar 7 '18 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.