Somehow this doesn’t work and can’t find a solution. (Unityscript)
#pragma strict
class Container {
public var theItems = new Array();
}
private var myCont : Container[];
function Awake () {
myCont = new Container[1];
var someObject : GameObject = new GameObject("some");
myCont[0].theItems.Add(someObject);
}
The last line gives an error (NullReferenceException).
You’ve declared myCont with a size of 1 which means it fills it with null items. You need to create a new Container instance, populate it, and add that to your array as well.
Ok. got it.
So this would be the correct approach?
#pragma strict
class Container {
public var theItems = new Array();
}
private var myCont : Container[];
function Awake () {
myCont = new Container[1];
var c = new Container();
var someObject : GameObject = new GameObject("some");
c.theItems.Add(someObject);
myCont[0] = c;
}