Multidimensional Array Problem

Hello,
i have a quastion with a multidimensional array.

I’ll explain it a bit…

First i create my Array.

int[,,] voxel;

==================================================
Then i initialize it.

void Awake()
{
   voxel = new int[16,16,16];
}

==================================================
Next thing is to fill it up with Zero’s.

void Start()
{
   for(int x= 0; x < 16; x++)
   {
      for(int y = 0; y < 16; y++)
      {
         for(int z = 0; z < 16; z++)
         {
            voxel[x,y,z] = 0;
         }
      }
   }
}

==================================================
After that i check if some of them are “1”.

void Update()
{
   for(int x= 0; x < 16; x++)
   {
      for(int y = 0; y < 16; y++)
      {
         for(int z = 0; z < 16; z++)
         {
            if(voxel[x,y,z] == 1)
            (
               GenerateTriangleAtPosition(new Vector3(x,y,z))
            )
            else
            (
               DeleteTriangleAtPosition(new Vector3(x,y,z))
            )
         }
       }
    }
}

==================================================
So the problem is that i couldn’t enter higher values in the “voxel” Array like

voxel[11,13,2] = 1;

As they would never have been created…

I think something is being lost in translation here… can you try explaining the problem again in more detail?

you appear to be creating a 3d array of 0’s, then you check if any are 1… so just set the indices you want to be 1’s before you check which indices are 1’s :face_with_spiral_eyes:

For starters, you don’t need to prefill an array with zeroes as “voxel = new int[16,16,16];” already does that. Int is a non-nullable type which means it’s default value is always 0;

Other then that

How do you mean they would never have been created? As far as I can tell you never even try to fill the array with 1’s :open_mouth: