# How to get LineRenderer coordinates?

I am trying to get the coordinates or positions that are generated at the time I draw with linerenderer, but it gives me an error.

This may be a rookie mistake and I am not using the Linerenderer's methods well. I would be very grateful for your help.

LineRenderer.GetPosition index out of bounds! UnityEngine.LineRenderer:GetPosition(Int32) sendData_Figura:Trazo(Int32) (at Assets/sendData_Figura.cs:115) sendData_Figura:Update() (at Assets/sendData_Figura.cs:93)

public LineRenderer  line;
public static int contadorTrazo = 0;

void Update(){
Trazo();
}

void Trazo() {
line = line.GetComponent<LineRenderer>();
}

• "it gives me an error" - great! Error messages are extremely useful in tracking down the source of the problem. What specific error does it give? We can't see anything you don't show us - including where you define your line variable. – DMGregory Sep 3 '19 at 3:18
• @DMGregory ese es el error que me esta dando – Nicolas Flores Muñoz Sep 3 '19 at 3:25

First, this line does nothing of use:

line = line.GetComponent<LineRenderer>();


line already points to your LineRenderer. You don't need to say "assign line to continue being itself" ;)

Second: your problem is just that you're continuing past the end of the line.

LineRenderer.GetPosition index out of bounds!

This means yo tried to access, say, point number 5 in a line that contains only 4 points. There's no sensible answer Unity can give you here, so it throws an error to tell you to correct your question.

You need to either stop incrementing contadorTrazo when you reach the last point in the line, or wrap back around to the beginning / bounce back / whatever behaviour is appropriate for your application:

void Trazo() {

} else {
// What do you want to do at the end of the line?
// Maybe restart at zero?
contatorTrazo = 0;
}
}

• Thank you very much, what I am trying to do get the vertices or coordinates and recorder in a database. Seriously thanks for the help. – Nicolas Flores Muñoz Sep 3 '19 at 3:45