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
0
Question by timcommandeur · Nov 20, 2013 at 03:39 PM · arrayvoxelchunksmultidimensional

Access a multidimensional array inside an array

Hey all,

I am working on a voxel engine and I have an array of chunks, which is actually just a 4dimensional array of blocks. The first index in the array is a chunk index and the rest are the x, y and z indexes of the blocks inside the chunks. Now I would like to loop through all the chunk indexes and pass the 3 dimensional array inside the chunks to a method, but it gives me an error. Here is an example:

 Block[,,,] blockData = new Block[chunkIndexes.Length, chunkSizeX, chunkSizeY, chunkSizeZ];
 
 for (int i = 0; i < chunkIndexes.Length; ++i)
 {
     // Here I would like to pass the 3dimensional array to a method but it gives
     // me an error saying that blockData requires 4 indexes.
     DoSomeyhingWithTheChunk(blockData[i]);
 }

I want to avoid using a List or something like that, does anyone know how i can achieve passing the 3dimensional arrays to a method?

Comment
Add comment · Show 1
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 Cherno · Nov 20, 2013 at 06:08 PM 0
Share

I seem to remember that 2+dimensional arrays need the GetLength[n] command ins$$anonymous$$d of just Length. n is the dimension you are referencing. Hope that helps.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seregon · Nov 20, 2013 at 07:32 PM

I don't know of any way of doing exactly what you'd like to in c#, you could probably write a method for cutting up an array like that, but it would involve effectively copying bits of the array, which is rather inefficient.

The closest solution (other than a List) would be an array of arrays:

     Block[][,,] blockData = new Block[chunkIndexes.Length][,,];
     for(int i = 0; i < chunkIndexes.Length; i++)
     { Block[i] = new Block[chunkSizeX, chunkSizeY, chunkSizeZ]; }
      
     for (int i = 0; i < chunkIndexes.Length; ++i)
     {
     // Here I would like to pass the 3dimensional array to a method but it gives
     // me an error saying that blockData requires 4 indexes.
     DoSomeyhingWithTheChunk(blockData[i]); }

Alternatively, you could pass the block index into the function as an argument, and have the function only operate on the that block, while passing it the entire array as a parameter.

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to load stacking chunks on the fly? 1 Answer

Multidimensional array of objects in C# 1 Answer

Push Custom Class to Array (JavaScript) 1 Answer

Clear 1 field of Transform array 1 Answer

Questions about voxel terrain(loading/saving and optimizing performance) 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