I have two scripts… One called myScript (javascript) on a GameObject
myScript.js
#pragma strict
public var array1 : int[];
public var array2 : int[,];
function Start()
{
Debug.Log(array1.Length);
Debug.Log(array2.Length);
}
and a simple editor script called myEditorScript (also javascript).
myEditorScript.js
#pragma strict
@MenuItem ("GameObject/AllocateArrays")
static function Allocate()
{
var goComponent : myScript = Selection.activeGameObject.GetComponent(myScript) as myScript;
if(goComponent !=null)
{
goComponent.array1 = new int [10];
goComponent.array2 = new int [10,10];
Debug.Log("Arrays initialized. "+goComponent.array1.Length+" "+goComponent.array2.Length);
}
}
With the GameObject containing the myScript component selected running the editor script from the GameObject drop down menu produces
“Arrays initialized. 10 100 as it’s output.”
Upon pressing the Play button I get 10 as the length of array1 but a null reference for the size of array2 as output from myScript. My question is how on earth do you allocate a multidimension array from an editor script? I had planned on storing some long term baked data so I didn’t have to regenerate it each runtime.
Any help would be much appreciated.