- Home /
Why is my array null?
Hi,
I'm creating an array, filling it with stuff, yet it's Null, according to Debug.Log(). What's going on?
var board:GameObject[,];
var movableBlockType:GameObject;
function Start()
{
board = new GameObject[3,3];
board[1,1] = movableBlockType;
Debug.Log(board);
}
And i get a "Null" in the console from the Log function
Are you sure you get Null
output from the above script and not from some other script? Apart from lack of targetBlockType
declaration in code above, your script should work without any problem.
yup,
sorry, i put the script together from a longer script, that's why I confused the Variables
yeah, when I double-click the Null in the console output, I end up at the line with the debug function.
Try outputting a particular element of the array. I don't think logging 'board' on its own will actually give any results.
Debug.Log
on any type uses ToString()
method. If it is not overloaded for particular type, then actual type name will be displayed (from Object.ToString()
). For example, the above script should display UnityEngine.GameObject[,]
@Somian - you changed line 7, but copied too much :) Remove :GameObject