- Home /
LineRenderer is not visible
I'm developing a 2D game by using Unity 4.3 and using Line Renderer. I'm setting start and end points and see the line on the screen without a problem.
However, after adding a big sprite as a background on my screen, the line is not visible anymore. I see it when I remove the background from my screen.
Following ones didn't work for me?:
rope.sortingOrder = 10;
rope.GetComponent(SpriteRenderer).sortingLayerName = "GameArea";
Any suggestion will be appreciated.
Answer by oktemre · Feb 22, 2014 at 12:29 AM
Solved by changing z position of background from 0 to 10. I hope this helps someone.
Saved my night, after 2 days of pain :) Thanks you very much
Yes changing the z position solved the problem for me thanks very much :). I wonder this is the case??
Answer by Prosto_Lyubo · Aug 16, 2014 at 05:35 PM
sortingLayerName + sortingOrder, if You work in 2D environment will work correctly only if You will assign Material with Sprites shader. In Your assets create new material, then in Inspector under Shader list pick: Sprites->Diffuse. Drag&Drop created material to Materials slot of LineRenderer.
Very useful information here that I did not see elsewhere. In my case I had a standard shader attached to my line material which worked in most cases. I could not figure out why the lines did not correctly render when under a Canvas though. Switching to a sprite shader fixed the issue! Thanks!
Thanks, by changing Sprites>Diffuse fixed that, Its not visible before caused by using standard shader material which disappear on certain camera angles
Thanks! it solved. I guess it's something internal Unity shader code.
This should be the accepted answer. Sorting layers are always better than changing the z value of elements in 2d.
It's really weird how Line Renderer doesn't have the Default - Line material automatically. I wonder if it's a bug.