- Home /
GameObjects in multidimensional Arrays
guys i need your help, it seems some alien lifeform has pulled the simplest coding skills from my brain:
when i do the following as a declaration:
public int sizeA = 10;
public int sizeB = 15;
private GameObject[][] objects;
the compiler wont let me do this in my start() ;
objects = new GameObject[sizeA][sizeB];
i get an error: Assets/Scripts/CubePlane.cs(25,40): error CS0178: Invalid rank specifier: expected `,' or `]'
i guess i miss the forest, standing in front of all the trees here, what do i do wrong ?
thx in advance guys chris
Answer by shaderop · Oct 10, 2012 at 06:12 PM
That's because you're using jagged arrays, which are supposed to be initialized like so:
objects = new GameObject[sizeA];
for (int i = 0; i < sizseA; ++i)
objects[i] = new GameObject[sizeB];
You're probably better off using multi-dimensional arrays:
private GameObject[,] objects;
objects = new GameObject[sizseA,sizeB];
i just found that out thank you ( see post below ^_^, ) i already used a jagged array within my code.. hm maybe check that againg, thanks again !
Answer by Nerdmigo · Oct 10, 2012 at 06:13 PM
ok i think i found the answer for myself: i used a so called "jagged array" ; which is GameObject[][] and you cant, for whatever reason, initialize the way i did
... however ... when using a true multidimensional array, corresponding to c# syntax you can do the following:
private GameObject[,] objects;
objects = new GameObjects[sizeA,SizeB];
that works fine...
$$anonymous$$ultidimensional array is not showing up in inspector? Is there any way to show game objects in inspector?
Answer by z25assassins · Apr 06, 2017 at 10:13 PM
Here is the C# documentation for arrays, could be useful for you. https://msdn.microsoft.com/en-us/library/aa287601(v=vs.71).aspx
Your answer

Follow this Question
Related Questions
Transport unknown amout of objects with GameObject array 0 Answers
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers
Spawning GameObjects with help of classes --- Attaching classes to GameObjects 1 Answer
Can one specify the parent of a gameobject in an array? 2 Answers
New Object Pooling Problem 1 Answer