Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question CreateEntites with correct SharedComponentData value

Discussion in 'Entity Component System' started by felbj694, Oct 7, 2023.

  1. felbj694

    felbj694

    Joined:
    Oct 23, 2016
    Posts:
    35
    Having different values of a SharedComponentData will result in entities being put in different chunks.
    I would like create a bunch of entities using EntityArchetype but with different shared component values for some.
    Now i need to first create the entities (structural changes) then set the shared value (another structural changes).

    Code (CSharp):
    1. EntityArchetype archetype = state.EntityManager.CreateArchetype(...)
    2. NativeArray<Entity> entities1 = state.EntityManager.CreateEntity(archetype, num, Allocator.Temp);
    3. state.EntityManager.SetSharedComponent(entities1, new MySharedComponent
    4. {
    5.     Value = 111
    6. });
    7. NativeArray<Entity> entities2 = state.EntityManager.CreateEntity(archetype, num, Allocator.Temp);
    8. state.EntityManager.SetSharedComponent(entities2, new MySharedComponent
    9. {
    10.     Value = 222
    11. });
    It would be nice to somehow modify the archetype to reflect the change of shared component data.
    I can stuff the commands in an ECS to avoid the sync points but data will still be shuffled around unnecessarily.