Search Unity

Probably A Quick Question About Native Array Bounds Issue

Discussion in 'Entity Component System' started by Filter_Feeder, Jul 1, 2021.

  1. Filter_Feeder

    Filter_Feeder

    Joined:
    Oct 19, 2017
    Posts:
    45
    I'm very new to DOTS, and I'm tyring to instantiate some entities to keep in a native array for future use. I use the code below, but when I run it it says that indicies are out of bounds. For debugging purposes, I simply set the index to be 0 at all times in the loop, but it's still apparently out of bounds even though I create a 1000 unit array ju the line above.

    Code (CSharp):
    1. public NativeArray<Entity> CreateToxels(int x, int y, int z)
    2.     {
    3.         toxelArray = new NativeArray<Entity>(1000, Allocator.Persistent);
    4.         for (int i = 0; i < x*y*z; i++)
    5.         {
    6.             int[] pos3d = Get3DPosition(x, y, z, i);
    7.             toxelArray[0] = InstantiateEntity(pos3d[1], pos3d[2], pos3d[3]);
    8.         }
    9.         return toxelArray;
    10.     }
     
  2. Filter_Feeder

    Filter_Feeder

    Joined:
    Oct 19, 2017
    Posts:
    45
    I tested the same thing, but replaced it with normal arrays, still didn't work. I then changed it to a normal array of float. Either I'm stricken with classic code blindness, or there's something else going on which I'm missing. Does it have something to do with the fact that I'm inheriting from JobComponentSystem?
     
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    Which array is out of bounds?
     
  4. Filter_Feeder

    Filter_Feeder

    Joined:
    Oct 19, 2017
    Posts:
    45
    The toxelArray, at line 7.
     
  5. PeppeJ2

    PeppeJ2

    Joined:
    May 13, 2014
    Posts:
    43
    Are you sure pos3d isn't the one out of range?
     
    MNNoxMortem likes this.
  6. Filter_Feeder

    Filter_Feeder

    Joined:
    Oct 19, 2017
    Posts:
    45
    No, I'm not. I think you pointed out some temporary blind spot for me, thanks a lot! I'm so embarassed now that I didn't see it myself :) Thanks again!
     
    MNNoxMortem likes this.