Making Array Values Equal to Instantiated Object

I am trying to make an array of GameObjects associated with a clone of an object which is initiated on start. Here’s the code that works:

for (int i = 0; i < 10; i++) {
Instantiate(roadPiece, new Vector2(0, i + .5F), Quaternion.identity);
}

As you’d expect, creates a line of ten clone objects at .5 y-coordinate higher than the previous one. Makes a nice little line. However, what I want it to do is to take these instantiated obejects and assign them a value in an array of GameObjects. The above works fine, but the below gives an “Object reference is not set to an instance of an Object” error after spawning the first clone, and does not populate the array with “1”.

for (int i = 0; i < 10; i++) {
roadLength = Instantiate(roadPiece, new Vector2(0, i + .5F), Quaternion.identity) as GameObject;
}
Any idea what’s causing the error? Thanks a lot!

Make sure array is allocated roadLength = new GameObject[10];