I've created a square using linerenderer but my problem now is that the line is not smooth. see below picture. I've tried enabling anti-aliasing and setting lr.numCapVertices to no avail.

enter image description here

 private void DrawLine()
GameObject myLine = new GameObject();
myLine.transform.position = start;
lr = myLine.GetComponent<LineRenderer>();
lr.material = new Material(Shader.Find("Sprites/Default"));     
lr.positionCount = 4;
lr.startWidth = .1f;
lr.endWidth = .1f;

lr.SetPosition(0, new Vector3(1, 0, 0));
lr.SetPosition(1, new Vector3(2, 0, 0));
lr.SetPosition(2, new Vector3(2, -1, 0));
lr.SetPosition(3, new Vector3(1, -1, 0));
lr.loop = true;

Gradient gradient = new Gradient();
    new GradientColorKey[]
        new GradientColorKey(Color.red, 0.25f),
        new GradientColorKey(Color.green, 0.50f),
        new GradientColorKey(Color.blue, 0.75f),
        new GradientColorKey(Color.yellow, 1f),
        new GradientAlphaKey[] { new GradientAlphaKey(1f, 0.0f)

lr.colorGradient = gradient;



Well I don't exactly know the cause of the problem but when i try to manipulate the values of linerenderer's positions, I find that when gap between the point is less then the value of 1 (-1 or 1) then we will get this weird behaviour.

however, when I increase the gap between the points then the line became crispy smooth.

Here are the some test results.

First Result

Second Result

Third Result

Now I understand completely that it is not a solution to the problem, And I am glad to know the explaination myself from anyone who know the reason that why is this happening but for now just change the position of your linerenderers points with distance greater than 1 unit.

  • \$\begingroup\$ Thanks for explaining bro if i set the unit to 1 it is not smooth. But i'll try to get a explaination why it is not smooth when setting the unit to 1. \$\endgroup\$ – Newboy11 Mar 20 '19 at 7:03
  • \$\begingroup\$ My advice is to avoid using line renderer whenever possible. It's a relatively poorly implemented tool. You should also be aware it's just drawing quads and connecting them by (optionally) rounded edge vertices. Depending on your use case, you're better off having a sprite. If you need color manipulation, a custom shader. But if you're not familiar with those topics then you can push ahead with line renderer. Just don't get frustrated with yourself if it doesn't work like you intend. \$\endgroup\$ – gjh33 Mar 20 '19 at 13:30

Your Answer

