- Home /
Object not set to an instance of an object, but the variable is already declared
hi, look at that :
var listOfFloors : Array[ , ];
var firstFloor : GameObject;
var objs : GameObject[];
private var hit : RaycastHit;
var isOk1 = false;
var isOk2 = false;
var floorsToList : GameObject[];
function Start()
{
floorsToList = gameObject.FindGameObjectsWithTag("floor");
var tx : float;
var ty : float;
var fx : float;
var fy : float;
fx = firstFloor.transform.position.x;
fy = firstFloor.transform.position.z;
for(m = 0; m < 15; m++)
{
for(i = 0; i < 10; i++)
{
tx = fx + 5*m;
ty = fy + 5*i;
var positionT = new Vector3(tx,0,ty);
objs = GameObject.FindSceneObjectsOfType(typeof(GameObject));
for (go in objs)
{
if (go.transform.position == positionT)
{
listOfFloors[m, i] = new Array(go, m, i);
Debug.Log("a cube has been saved");
break;
}
}
}
}
lastFloor = listOfFloors[startEnemy[0], startEnemy[1]];
}
I don't understand, this generate an error "Object not set to an instance of an object" (at line 54 & 122) These objects are in the scene.
Thanks
Answer by aldonaletto · Dec 30, 2011 at 10:21 PM
I don't have the slightest idea of what this script is trying to do, but I suspect you may have problems with the instruction if (go.transform.position == positionT): probably only the firstFloor object will pass the test.
Anyway, in my tests the error was generated by the listOfFloors variable: it's declared, but no space is allocated to it. You should change the first line to something like this :
var listOfFloors = new Array[15,10];
This declares and initializes the array - change the array size, if it's not enough.
Your answer
Follow this Question
Related Questions
Referencing Objects in Unity 1 Answer
InstanceIDtoObject namespace? 1 Answer
How would I set an instance of an object? 1 Answer
object instances 0 Answers
Get instance of exisiting object 1 Answer