I make a curved line with line renderer. and a sphere move along it. i want to draw a line only behind the sphere.

so i do something like this.

`` lr.positionCount = 256;

    while (delta < time)
        lr.SetPosition(i++, curPos);

        yield return new WaitForFixedUpdate();


and the problem is, because of i set the size of Positions 256, if time is short, there are zero vectors in position. so line renderer draw meaningless line.

is there a way to set PositionCount dynamically like List? or any good way to not draw if positions are zero?

  • \$\begingroup\$ you can reset positionCount in loop. something like lr.positionCount = i++; and it works like List but i don't know how it works inside... \$\endgroup\$ – Hree Nov 25 '19 at 12:45
  • \$\begingroup\$ Possible duplicate of Enable / Disable LineRenderer Points. You could also clip the line in the shader, similar to this Q&A, setting the cut-off point as a material uniform so it moves as your script dictates. \$\endgroup\$ – DMGregory Nov 25 '19 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.