Search Unity

Feedback [FeatureRequest] Chunk.GetValueReinterpret<T>(Type, Entity, int) and Chunk.IndexOf(Entity)

Discussion in 'Entity Component System' started by Guedez, Oct 18, 2020.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    I mean, I can do this huge thing:
    Code (CSharp):
    1.         ArchetypeChunk Chunk = EntityManager.GetChunk(Entity);
    2.         NativeArray<Entity> Entities = Chunk.GetNativeArray(GetEntityTypeHandle());
    3.         int index = -1;
    4.         for (int i = 0; i < Entities.Length; i++) {
    5.             if (Entities[i] == Entity) {
    6.                 index = i;
    7.                 break;
    8.             }
    9.         }
    10.         if (index == -1) {
    11.             return default;
    12.         }
    13.         for (int i = 0; i < Inputs.Length; i++) {
    14.             EntityValueArray[i] = Chunk.GetDynamicComponentDataArrayReinterpret<float>(GetDynamicComponentTypeHandle(Inputs[i]), 4)[index];
    15.         }
    But surely the internal code can optimize some stuff, like easier way to get the entity index or not needing to allocate the whole array of reinterpreted values for a single one.
     
    slims and cultureulterior like this.