Rect Array in Javascript

Trying to create an array of Rect positions, it doesn’t give an errors until I tried to put in play mode.

private var invPos : Rect[];
invPos[1] = Rect (110, 0, 75, 75);
invPos[2] = Rect (190, 0, 75, 75);
invPos[3] = Rect (270, 0, 75, 75);
invPos[4] = Rect (350, 0, 75, 75);

The error I’m getting is - Object reference not set to an instance of an object.

Everything I’ve read says this should work. Is there something special about Rects?

Solved: I wasn’t declaring it correctly, should have been;

var invPos = new Rect[4];

Without my beer goggles on, it’s got nothing to do with type inference. You’re never initializing the array in the first place, and the compiler does not complain when you try to add elements to it. This works:

#pragma strict

private var invPos : Rect[];

function Start () {
    invPos = new Rect[4];

    invPos[0] = Rect (110, 0, 75, 75);
    invPos[1] = Rect (190, 0, 75, 75);
    invPos[2] = Rect (270, 0, 75, 75);
    invPos[3] = Rect (350, 0, 75, 75);
}

function Update () {
    for (foo in invPos)
    {
	Debug.Log(foo.left);
    } 
}

You should init your array

private var invPos : Rect[] = new Rect[4];