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 Monko · Sep 06, 2013 at 05:33 PM · arraylistmultidimensional array

Creating a multidimensional array List

In my game, I need to make a List that contains a 3 dimensional array of floats. I can create a list like this:

 List<float> testList = new List<float>();

I also know how to create a multidimensional array, like this:

 float[,,] testarray = new float[32,32,32];

The problem is I don't know how to make testList contain float[,,], rather than just a float. My ultimate goal is to hypotheticly be able to call values from the List like this:

 foundvalue = testList[2][17,24,8];

Does anyone know how to create a special List/array like this? Ive looked online, and the closest thing I have found is a List within a List, but that is not what I need.

(Just so you know, I am working in C#, and have already called "using System.Collections.Generic;")

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

2 Replies

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

Answer by perchik · Sep 06, 2013 at 05:39 PM

Have you tried

 List<float[,,] > testList = new List<float[,,]>(); 
Comment
Add comment · Show 4 · 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 Monko · Sep 06, 2013 at 06:00 PM 1
Share

Wow, thanks perchik! I Can't believe I didn't think of that! After experimenting for a while, I have figured it out.

Here is what I have discovered: To create the multidimensional array List,do what perchik mentioned

 List<float[,,] > testList = new List<float[,,]>(); 

Now, to put float[,,] into the List, you do this:

 float[,,] testarray = new float[32,32,32];
 testList.Add (testarray);

To edit testarray, you have to define which float[,,] in the list you want to edit first:

 testList[0][17,24,7] = 1;

Its slightly confusing, because your using elements from Lists AND arrays, but I think I have figured it out. Thanks again perchik!

avatar image Noxury · Apr 24, 2016 at 01:14 PM 0
Share

@perchik Hmm it will not show up in the inspector although i have marked it as public (using 5.3.4f)

avatar image Straafe Noxury · Oct 16, 2018 at 12:28 AM 0
Share

Did you serialize the field?

avatar image Bunny83 Straafe · Oct 16, 2018 at 12:58 AM 0
Share

The post you replied to is two years old. Also multidimensional arrays can't be serialized by Unity and therefore can never show up in the inspector.

avatar image
1

Answer by roojerry · Sep 06, 2013 at 05:38 PM

How about a Dictionary with and integer key and a multidimensional array for the value. like:

 Dictionary<int, float[,,]> testDict = new Dictionary<int, float[,,]>();


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

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

Related Questions

A node in a childnode? 1 Answer

Changes not being saved in the Inspector Editor 1 Answer

Keep adding targets to a list 2 Answers

Difference between Static, Dynamic, and Built-In Arrays 1 Answer

Adding and Removing to a Inbuild Array 2 Answers


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