I'm trying to draw some lines in the editor between objects. As I want the system to be dynamic, I'm trying to create it so you can simply insert objects from the editor, and the line will update automatically without editing code.
I've created following code:
public class PathLines : MonoBehaviour {
public GameObject[] pathPoints;
// Update is called once per frame
void Update () {
for(int i = 0; i < pathPoints.Length; i++)
{
if(i != pathPoints.Length)
{
Handles.DrawLine(pathPoints[i].transform.position, pathPoints[i + 1].transform.position);
} else
{
Handles.DrawLine(pathPoints[i].transform.position, pathPoints[0].transform.position);
}
}
}
}
And then inserted currently 3 objects to the array in the editor. I do however get the NullException error at the first pathPoints[i], and no matter what I seem to do fixes it. How do I get rid of this error?
(Edit)Flagged as duplicate: My question is concerning getting a NullException error after inserting objects into an array through the editor. Shouldn't this automatically initialize the array, and thereby not cause the Null error?