Search Unity

Bug ChunkComponent variable value not updating in Inspector

Discussion in 'Entity Component System' started by Hokuin, Jul 6, 2021.

  1. Hokuin

    Hokuin

    Joined:
    Oct 6, 2020
    Posts:
    1
    Hello. During my scouting on DOTS and checking all possibilities I've probably encountered problem with manipulating chunk components. Look at the code below, which is in Start method of my entity management MonoBehaviour:

    Code (CSharp):
    1.  EntityArchetype myarchetype = entityManager.CreateArchetype(typeof(LevelComponent), typeof(YComponent));
    2.         var entitiesOfArch = entityManager.CreateEntity(myarchetype, 100, Allocator.Temp);
    3.         foreach (var ent in entitiesOfArch)
    4.             entityManager.AddChunkComponentData<YComponent>(ent);
    5.  
    6.         ArchetypeChunk aChunk = entityManager.GetChunk(entitiesOfArch[23]);
    7.         entityManager.SetChunkComponentData<YComponent>(aChunk, new YComponent { yy=314});
    8.  
    9.         YComponent c = entityManager.GetChunkComponentData<YComponent>(entitiesOfArch[23]);
    10.         Debug.Log(c.yy);
    11.  
    12.         entitiesOfArch.Dispose();
    Debug.Log prints 314, as predicted. However, in Unity inspector that YComponent.yy remains 0 (default value) in both "normal" component and chunk component.

    After a couple of research, I noticed that the problem exists only when in one entity I have 2 components of the same type (one as normal, another one as chunk component). When I changed YComponent in first line to XComponent (which is quite the same):

    Code (CSharp):
    1. EntityArchetype myarchetype = entityManager.CreateArchetype(typeof(LevelComponent), typeof(XComponent));
    2.         var entitiesOfArch = entityManager.CreateEntity(myarchetype, 100, Allocator.Temp);
    3.         foreach (var ent in entitiesOfArch)
    4.             entityManager.AddChunkComponentData<YComponent>(ent);
    5.  
    6.         ArchetypeChunk aChunk = entityManager.GetChunk(entitiesOfArch[23]);
    7.         entityManager.SetChunkComponentData<YComponent>(aChunk, new YComponent { yy=314});
    8.  
    9.         YComponent c = entityManager.GetChunkComponentData<YComponent>(entitiesOfArch[23]);
    10.         Debug.Log(c.yy);
    11.  
    12.         entitiesOfArch.Dispose();
    Debug.Log prints 314 like earlier, but this value is also visible in Inspector, in YComponent area.