- Home /
Value of 2d Array from external script
Good day, gentlemen.
So my question is regarding the new feature in Unity scripting - long awaited multidimensional arrays.
So, the problem. I have a script(script1) which is assigned to some object(object1). In this script1 2d array is created
var Array = new int[6,6];
and some values are inserted there.
I can manipulate the values in this array in script1 without any problem any way i like.
Now, i have a script (script2) assigned to some other object(object2), in which i try to call the values of the array in script1 like this:
print ("Print value of array element:"+GameObject.Find("object1").GetComponent(script1).Array[3,5])
So, i get the error!: MissingFieldException: Field 'System.Int32[,].' not found. Which is strange, as i can call any other variable like that and !even 1 dimensional array! with no problem! But with 2d array i get this error.
Is there a bug with multidimensinal arrays in unity still, or i am doing something wrong?
Thanks!
Not sure this is a clue, but it's generally bad form to use variables with the exact same spelling and Case as a reserved word, like Array
Answer by Eric5h5 · Mar 30, 2011 at 06:31 AM
Multidimensional arrays don't work with dynamic typing for some strange reason, though it's generally better to avoid dynamic typing anyway. Using generics is the easiest way to do that.
GetComponent.<script1>()
instead of
GetComponent(script1)
Your answer
![](https://koobas.hobune.stream/wayback/20220613115546im_/https://answers.unity.com/themes/thub/images/avi.jpg)