I am creating a drawing feature using line renderer. Currently I am able to draw lines using the mouse cursor on a UI image as a background. However, I am noticing that if I am drawing the line outside certain positional constraints, the line does not become visible. Furthermore, the line seems to be rendered behind the UI image when viewed at certain angles (even when the line itself is physically in front of the UI image). The link below demonstrates this issue (with code and settings). Can someone help me with what is causing this issue? Open to any suggestions, thanks.
Looks like you just have ambiguity in the sorting order. Here’s some relevant reading:
Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:
In short, as far as the Standard Rendering Pipeline,
-
The default 3D Renderers draw stuff according to Z depth - distance from camera.
-
SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties
-
UI Canvas Renderers draw in linear transform sequence, like a stack of papers
If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:
- identify what you are using
- search online for the combination of things you are doing and how to to achieve what you want.
There may be more than one solution to try.
For instance, you may even use multiple co-located cameras (along with different Layers and LayerMasks drawn to different-depth Cameras) to more-explicitly control apparent draw ordering.
Additional reading in the official docs:
And SortingGroups can also be extremely helpful in certain circumstances:
Other rendering pipelines may have other ways of layering (HDRP and URP). Go see the latest docs for details.
There’s lots of third party open source packages available as well, such as this:
Thank you so much for your help! Having the “Order in Layer” for the line set to 1 and “Order in Layer” for the UI Canvas set to 0 fixed the issue. Your response is very informative!
I was having the same problem but instead of a UI Canvas background, the issue was with just a normal plane mesh as background.
Just for future reference, what solved it for me was to change in the plane’s material settings, in Render Queue switch from From Shader (the default) to Geometry. Since all I wanted was the line to always draw on top of the plane, this was a good enough solution.