Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NativeMultiHashmap vs 2 NativeArrays to represent a very large grid.

Discussion in 'Entity Component System' started by MintTree117, Apr 2, 2020.

  1. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    I am trying to create a unit avoidance system, somewhat similar to the Unity DOTS boids example. I want to group entities into cells based on their positions.

    However, I have read that hashmaps can be slow for very large sets of data because the keys are stored randomly, and for something like an avoidance system its better to have close cells together in memory.

    I could have an array of entities, and then an array of int2 where each int2 is a starting and end index inside the entity list. This way, positions near each other are close in memory.

    Is this correct thinking?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,223
    An array of entities doesn't make the components adjacent to each other.
     
    MintTree117 likes this.
  3. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    Good point.