class Data{
public var x : float;
public var y : float;
public var z : float;
public var name : String;
}
class DataClass{
var allObjects:Data[] = new Data[0];
function DataClass() { }
}
var objectData:DataClass;
function Start(){
var foundObjects = GameObject.FindObjectsOfType(Transform);
objectData.allObjects = new Data[foundObjects.Length];
yield WaitForSeconds(1);
for(var num:int;num<foundObjects.Length;num++){
objectData.allObjects[num].x = foundObjects[num].position.x; //Error here
objectData.allObjects[num].y = foundObjects[num].position.y;
objectData.allObjects[num].z = foundObjects[num].position.z;
objectData.allObjects[num].name = foundObjects[num].name;
}
}
When I run this and the objectData array isn’t displayed in the Inspector, I get “NullReferenceException: Object reference not set to an instance of an object”. This also happens if I remove the yield or make the array static or private.
If I select the gameobject with the script, so I can see the array in the Inspector, it works.