I have 3 cameras and 3 canvases.
- Back Camera: depth = -5, Back Canvas: Sorting layer - BackLayer,
- Camera: depth = 0, Middle Canvas: Sorting layer - MiddleLayer,
- Camera: depth = 10, Front Canvas: Sorting layer - FrontLayer,
Orders in canvases are also set (for
SpriteRenderers, images, ui etc.)
Back is for a background image and stars, middle for mountains and front for the UI. Everything is working perfectly with one exception:
No matter where I draw lines with a
LineRenderer - they're always at the front of everything (each canvas).
The one situation where the line moves deeper is when I set it's points Z to some huge values like 30000 and then - they're just behind everything.
My goal is to place these lines along with the background image and stars on the BackLayer or BackCanvas.
What I've already tried:
LineRenderersorting layer and it's order from the code. I read somewhere on Unity forums that lineRenderer has to have a special material for this to work but I tried most of them - not working.
I also tried setting their positions manually, from the inspector, from the code, incrementally in the
Update()method - they're always in front or complately hidden (with huge numbers mentioned above).
I tried assigning them to different canvases (back, middle, front) as children didn't work too.
On Unity forums I also read a post which says that we shouldn't use sorting layers with linerenderer and use only Z positions.
If someone has any experience with this, I would be grateful. I really have no idea if I'm doing something wrong or what.