I am trying to set up a built in array and continue to get the error:
The built in array itself works fine and I can change the size in the inspector with no problems. I can even reference the individual data fine via script at this point. The problem comes when I try to resize the array in script. The array length shows the proper size and the fields update in the inspector after the resize, but every slot I try to access in code returns the null reference error above.
Here’s the code:
class myClass
{
var variable1 : int = 1;
var variable2 : int = 2;
var variable3 : int = 3;
}
var myClassArray : myClass[];
function Start ()
{
//myClassArray is set to 5 in the inspector manually
Debug.Log(myClassArray.length); //This returns 5 as expected
Debug.Log(myClassArray[0].variable1); //This returns 0
myClassArray = new myClass[200]; //This works fine and updates the fields in the inspector as expected
Debug.Log(myClassArray.length); //This returns 200
Debug.Log(myClassArray[0].variable1); //Should return 1, but this throws the error above even though the inspector shows the correct data
}
Any suggestions as to what’s going wrong would be greatly appreciated. Thanks.