- Home /
Question by
tlrpi · Mar 29, 2012 at 07:34 PM ·
errornullreferenceexception
NullReferenceException trouble
Having some trouble fixing this "NullReferenceException: Object Reference not set to instance of an object". I'm sure its something silly, but I'm new to Unity and can't see how to fix it. Any help is much appreciated. Here is the relevant code, the error occurs at the line "tiles.push(floorPosition)" :
var floorPosition : Vector3;
var tiles : Array;
function Grid(){
floorPosition = Vector3(-1005.4, 0, -1339.9);
tiles.push(floorPosition);
var tempXPos : float;
var tempZPos : float;
var tempPos = new Vector3(tempXPos, 0, tempZPos);
for (var i = 0; i < 141; i++){ //141 tiles in the X direction
tempXPos = floorXPos + (100*i);
for (var j = 0; j < 130; j++){ //130 tiles in Z direciton
tempZPos = floorZPos + (100*j);
tiles.Push(tempPos);
}
}
return tiles;
}
Thanks
Comment
Answer by DaveA · Mar 29, 2012 at 07:46 PM
It helps to tell us what line it's choking on, I'm betting this one:
tiles.push(floorPosition);
You need to allocate the array before this:
tiles = new Array();
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
NullReferenceException problem 2 Answers
Scripting error comes up when I press play 1 Answer
NullReferenceException 1 Answer