Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Nerdmigo · Oct 10, 2012 at 05:55 PM · gameobjectarraymultidimensional

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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];


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nerdmigo · Oct 10, 2012 at 06:15 PM 0
Share

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 !

avatar image shaderop · Oct 10, 2012 at 06:17 PM 0
Share

No problem. Good luck :)

avatar image
0

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...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Usama300 · Feb 01, 2021 at 02:53 PM 0
Share

$$anonymous$$ultidimensional array is not showing up in inspector? Is there any way to show game objects in inspector?

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges