2
\$\begingroup\$

I want to create a line renderer and also trail renderer that would follow touches but both must be rendered above my UI canvas — how can I do this?

I have tried this with the "screen space camera" mode and just came to know that it is not possible with screen space camera.

Is it possible by using line or trail with a "screen space overlay" canvas? If yes, then how could I make line/trail follow the touch position in such a setup?

I tried this before but i was not able to make it appear on screen rather it appeared on world as if it is ignoring the overlay canvas.Then I switched to screen space camera and this problem arose.

\$\endgroup\$
  • \$\begingroup\$ No, this is not possible with an "overlay" canvas. The nature of "overlay" is that its UI is drawn on top of your world objects like line & trail renderers. You need to use Screen Space Camera or World Space in order to get depth sorting and layering between your UI and non-UI objects. \$\endgroup\$ – DMGregory Oct 15 at 17:31
  • \$\begingroup\$ But i need to use Screen space overlay canvas for ui. So, no way to do this? \$\endgroup\$ – Anmol Deep Oct 16 at 3:48
  • \$\begingroup\$ What specific outcome do you want from the screen space overlay canvas? We might be able to help you find alternative ways of achieving that outcome. \$\endgroup\$ – DMGregory Oct 16 at 3:51
  • \$\begingroup\$ No nothing specific. I was just making an asset for somebody else who told me to use overlay canvas for ui. So, i was trying too. But now since there's no way to achieve this with overlay canvas. I have told him of the changes. \$\endgroup\$ – Anmol Deep Oct 16 at 11:09
1
\$\begingroup\$

If you want to render things in front of UI then you can't achieve this with "Screen space overly" here is the reason.

So we are having two choices to chose from:

  1. World space.
  2. Screen space - Camera.

For more information about canvas and canvas render more please visit here.


World space:

To achieve such a effect with world space its too easy to do, You just have to change sorting order or Sorting layer of the object to render it front or at back of the UI.

Now when we have to render Line Rendrer or Trail Rendrer in front of the UI, Then i have to change sorting order to some thing bigger then canvas sorting order, Let suppose canves sorting order is 0 then i have to change Line or Trail rendrer sorting order to some thing like 1 or anything bigger then 0.

Canvas Settings:

enter image description here

Trail Rendrer Settings:

enter image description here

Or we can achieve this using Sorting layer. In order to use sorting layer then you have to create multiple layers. By default there is only one layer called "Default".

To create more layer you can click on Sorting layer - Default and then Add Sorting Layer.... And then just add the layers you want...

enter image description here

enter image description here

Now unity will render sorting layer "Default" first then on top it Sorting layer "UI" will be rendered and the at last Sorting layer - Trail will be rendered.

For "Screen space - Camera" same mathod will be applied like in World Space.

I hope this will resolve the quires you have about sorting layer and sorting order and canvas render mode etc.

\$\endgroup\$
  • \$\begingroup\$ Thanks! for the detailed explanation. \$\endgroup\$ – Anmol Deep Oct 16 at 11:03
  • \$\begingroup\$ you are welcome. if this answer resolved your issue then consider accept the answer by pressing that tick sign under that voting system. And if you have question please let me know. I will be to help. \$\endgroup\$ – Swati Oct 16 at 12:37

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.