- Home /
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;")
Answer by perchik · Sep 06, 2013 at 05:39 PM
Have you tried
List<float[,,] > testList = new List<float[,,]>();
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!
@perchik Hmm it will not show up in the inspector although i have marked it as public (using 5.3.4f)
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.
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[,,]>();
Your answer
Follow this Question
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