Hello, I’ve found everything else I need, but I can’t find this little tidbit of how nested lists work in C#. How do I reference a specific piece? For instance, say I have a List<List<List>>. How do I reference the mesh in the Oth List inside the Oth List inside the Oth list? Basically I want to convert the contents to a three dimensional array to avoid presetting the 3d array size and filling in null values.
Is it as simple as: List[0][0][0]?
If so is adding to it as simple as List[0][0][0].add?
Okay, so I get that, the last bracket indicates the item itself. Then it takes a quadruple nested list to set up a list[ ][ ][ ] reference I can exchange easily into a 3d [,] array? How do I fill the list arrays to make it possible to add to say… list[4][16][4] … without getting an argument out of range error? Is there a better way to accomplish procedurally filling a very large 3d array you suggest?
I’m guessing that what you have is a 3d space broken up into cubes and some of those cubes have a mesh in them and some do not? Or something like that?
If you know ahead of time exactly how big each array will be you might just use regular arrays
Mesh[,] meshArray = new Mesh[xSize,ySize,zSize]
then to fill the 3d array you do something like:
foreach (Mesh m in lisOfMeshes) {
meshArray[m.x,m.y,m.z) = m;
}
Then if you wanted to iterate over all of them:
for (int x = 0; x< xSize; x++)
{
for (int y = 0; y < ySize; y++)
{
for (int z = 0; z < zSize;z++)
{
Mesh m = meshArray[x,y,z];
if (m!= null) //do something
}
}
}
Okay, so I avoided the nested lists altogether. That’s about right Jack, I don’t know how big they will come out to be however. I opted for two lists, one listing Vector3’s that are the 0,0,0 so-to-speak of the mesh I’m intending to store, the other obviously lists the corresponding meshes. I can then add to the lists as long as I need to and convert them to arrays when I need to look up the vector and use it’s index to grab the corresponding mesh of the same index.