LineRenderer just showing awful results

Hi,

I’m trying to draw the outline of 2d colliders in gameplay. As far as I know the only way to draw a line on Unity Free is to use linerenderer or to buy some linedrawer from the asset store.
LineRenderer gives awkward results because its meant to be 3D, here is what it looks like when I try to draw the outline of a BoxCollider2D:

42163-linerenderer.png

Is there any way how I can achieve this in unity free? I also should be able to draw the outlines of a circle and polygon, but it’s okay when I can implement these 2 later, I don’t need them right now.

I had the same problem. Using widthMultiplier instead of start-/endWidth fixed it for me.

134226-startendwidth.png

LineRend.startWidth = LineWidth;
LineRend.endWidth = LineWidth;

134227-widthmultiplier.png

LineRend.widthMultiplier = LineWidth;

Line renderer was simply not meant to draw multiple lines if any angle was less than or equal to 90. Line renderer prioritizes keeping the width constant but it can’t do a good job if the angle between two lines is less than or equal to 90 because it considers the width of the vertex. However you probably want the vertices like they would in a frame so you have a few options.

  1. Use multiple line renderers. I did this in my comment.

  2. Make your own mesh and use mesh renderer. For instance, you could use something like the following.

    public class NewBehaviourScript : MonoBehaviour {
    Mesh mesh;
    void Start() {
    MeshRenderer renderer=gameObject.AddComponent();
    renderer.material=new Material(Shader.Find(“Diffuse”));
    renderer.material.color=Color.red;

         MeshFilter filter=gameObject.AddComponent<MeshFilter>();
         mesh=new Mesh();
         mesh.vertices=new Vector3[8];
         mesh.triangles=new int[]{
             0, 1, 4,
             5, 4, 1,            
             1, 3, 5,
             3, 7, 5,            
             3, 2, 6,
             6, 7, 3,            
             2, 0, 4,
             6, 2, 4,   
         };
         mesh.uv=new Vector2[mesh.vertices.Length];
         mesh.RecalculateNormals();
         mesh.Optimize();
         filter.mesh=mesh;
     }
    
     public float z=0;
     public float xSize=1;
     public float ySize=1;
     float width=1f;
    
     void Update() {
         mesh.vertices=new Vector3[]{
             new Vector3(-width, -width, z),
             new Vector3(-width, width+ySize, z),
             new Vector3(width+xSize, -width, z),
             new Vector3(width+xSize, width+ySize, z),
    
             new Vector3(width, width, z),
             new Vector3(width, -width+ySize, z),
             new Vector3(-width+xSize, width, z),
             new Vector3(-width+xSize, -width+ySize, z),
         };
         mesh.RecalculateNormals();
     }
    

    }

@maccabbe :

  1. Use multiple line renderers. I did this in my comment.

This worked for me, but anyone still having this problem should update to Unity 5.5.0xb5 or later,
Unity seemed to have fixed this bug.