LineRenderer (strange bug)

Hello,
I have a pretty weird problem with the LineRenderer component:
I want to join each WayPoint (capsule) of my scene with LineRenderer in a progressive way. I managed to do it with the code below but each time it touches a WayPoint (capsule), a line is created to the point 0,0,0 for 1 frame before disappearing. I do not understand … my code is correct and does not mention doing that.135114-ma-capture-01-1.gif

my assumption is that it comes when I increment its size ‘’ lineRenderer.positionCount ++ "which makes me create a time 0,0,0 before the position changes.

Do you have an idea to avoid this temporary line please? Here is my code that
I commented the 5/6 lines of code concerned by the LineRenderer with ‘’ // here ‘’:

    LineRenderer lineRenderer;
    private int indexLine = 0;
    public float linearSpeed = 5;

    private void Start()
    {
        lineRenderer = gameObject.GetComponent<LineRenderer>();  //here
        lineRenderer.positionCount = 1;  //here
        lineRenderer.SetPosition(0, start.transform.position);  //here
        NavigateTo(start, end);
    }
    
    void Update()
	{
        if (currentPath != null && currentPath.Count > 0) 
		{
			if (moveTimeCurrent < moveTimeTotal)
			{
				moveTimeCurrent += Time.deltaTime;
				if (moveTimeCurrent > moveTimeTotal)
                    moveTimeCurrent = moveTimeTotal;
                var pointALongLine = Vector3.Lerp (currentWaypointPosition, currentPath.Peek(), moveTimeCurrent / moveTimeTotal);  //here
                lineRenderer.SetPosition(indexLine, pointALongLine);  //here
            } else
			{
				currentWaypointPosition = currentPath.Pop(); 
                if (currentPath.Count == 0)
                    Stop ();
                else
                {
                    lineRenderer.positionCount++; //here
                    indexLine = indexLine + 1; //here
                    moveTimeCurrent = 0;
                    moveTimeTotal = (currentWaypointPosition - currentPath.Peek()).magnitude / linearSpeed;
                }

I’d say it comes from the fact that in the else part, you are adding a new entry in the array without setting any value to it. So it gets default.

You could try to add the value and set it as the current value so it won’t show the full line for a frame again.

                 lineRenderer.positionCount++; //here
                 lineRenderer.SetPosition(lineRenderer.positionCount - 1, currentWaypointPosition);

This should add a new entry and set it as the last one.