Hello,
I created a jaggedArray in my game consisting of 30 Elements:
[var InventoryItems = MultiDim.JaggedGameObject[30];]
I assigned the first three values:
[InventoryItems[0] = new GameObject[5];
InventoryItems[1] = new GameObject[1];
InventoryItems[2] = new GameObject[1];]
I only want the player to have the third Array active at the start, so i did this:
[function Start(){
for(var I = 0; I < InventoryItems.Length; I++){
InventoryItems*[0].active = false;*
}
InventoryItems[2][0].active = true;
}
]
But the Console throws this error: “NullReferenceException: ObjectReference not set to an Instance of an object”.
Can anyone please tell me how to do this correctly?
Thanks
You’ve only made some GameObject arrays, you haven’t actually made any game objects. All of the entries in the arrays are null until you create/assign some game objects. i.e., inventoryItems[0][0] = new GameObject();
–Eric
No, I actually assigned them(Forgot to mention):
var LongKey:GameObject;
var RustyKey:GameObject;
var Saw : GameObject;
var CrossBow : GameObject;
(I dragged and dropped the gameobjects on the variables in the inspector)
edit to function Start:
Inventoryitems[0][0] = LongKey;
inventoryItems[0][1] = RustyKey;
InventoryItems[1][0] = Saw;
InventoryItems{2[0] = CrossBow;
But still I get the same error…
You still have null entries that you’re trying to refer to. All entries in all arrays must be defined if you want to use them.
–Eric