- Home /
Index Out of Bounds Line Render
So i get an error on path.SetPosition (i, newPos); saying index is out of bounds? I am not sure why or how to solve this. the variable newPos is a vector 3 updated as the game object follows pose. I know its working because instantiate an object when The gameobject pose is moving. I can also print the current vector 3 of the Newpos. so why the error? I just want to build a line render as the object moves to then carry that over to the next scene, but cant get pass this error
Thanks for the help in advance.
private Vector3 lastPos;
private Vector3 newPos;
private bool isMove;
private int i;
private LineRenderer path;
public GameObject wayPoint;
public GameObject pose;
void Start ()
{
i = 0;
path = GetComponent<LineRenderer> ();
StartCoroutine (trackMove ());
}
IEnumerator trackMove()
{
lastPos = pose.transform.position;
yield return new WaitForSeconds (0.5f);
newPos = pose.transform.position;
if (lastPos != newPos) {
Debug.Log ("Im moving");
path.SetVertexCount (i);
path.SetPosition (i, newPos);
i++;
}
else if (lastPos == newPos) {
Debug.Log ("not moving);
isMove = false;
}
StartCoroutine (trackMove ());
}
Answer by alfaro190 · Jul 07, 2015 at 05:49 PM
Figure it out. I couldnt have the vertex count and path position both equal to the same variable. Since the variable of vertex counts starts at 0 and the path position starts at 1. So I when it was updating it kept creating one more vertex that there was a position. to fix it I could either set vertex to one, but instead I created another int var and set that equal to 1.
So the path position is equal to one and the vertex count is equal to 0;
problem was solved
Your answer
![](https://koobas.hobune.stream/wayback/20220611225813im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Vertices Array only given in local coords? 1 Answer
Laser Render Reflect Angle incorrect 1 Answer
Making a ball move according to swipe of the mouse 0 Answers
how to find a point(vector2) between two points(Vector2) of a line (line renderer) 2 Answers
Need to find a point in a line using a percentage and a Vector3 list. 1 Answer