Array problem

I get null reference errors when getting or setting any variable in this array. I’ve tried both methods of setting the array size initially (as it is now)… and reconstructing the area with the commented line in function Awake() that you see below. What am I doing wrong?

Also if anyone knows a more elegant way of looping through all the objects than what I’m doing now (a simple counter… ) I would be very grateful. I suppose I could use a generic for loop…

    class ObjectData
        var x : float;
        var y : float;
        var z : float;
        var name : String;
     class MapData
       var _iLevel : ObjectData[];
       function MapData() { }

    private var myData : MapData;

function Awake () { 

        myData=new MapData();

        var gameObjects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
            	  myData._iLevel = new ObjectData[gameObjects.Length];
            	  for (var stats : GameObject in gameObjects) {
             	   myData._iLevel[count].x = stats.transform.position.x;
                   myData._iLevel[count].y = stats.transform.position.y;
              	   myData._iLevel[count].z = stats.transform.position.z;
               	   myData._iLevel[count].name =;


You need to create the ObjectData instances - inside the for loop at top do myData.ILevel[count] = new ObjectData(); You just have an array of references to object data that is null. In C# I think you could make this a struct and you would be ok, but it is a class here, so you need to allocate it.