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 AddSharedComponent<T>(EntityQuery, T) not working ?

Discussion in 'Entity Component System' started by Liquid_Nalee, Apr 24, 2021.

  1. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Code (CSharp):
    1. // This works
    2. var tiles = TilesQuery.ToEntityArray(Allocator.Temp);
    3. var commandBuffer = EcbSystem.CreateCommandBuffer();
    4. foreach (var tile in tiles)
    5.     commandBuffer.AddSharedComponent(
    6.         tile,
    7.         new GridGenerationComponent(GridGenerationPhase.End)
    8.     );
    9.  
    10. // This doesn't
    11. commandBuffer.AddSharedComponent(TilesQuery, new GridGenerationComponent(GridGenerationPhase.End));
    Not sure if i'm missing something here.
    Basicaly, I was trying set the shared component on all of my system's query entities.
    Using the AddSharedComponent<T>(EntityQuery, T) doesn't work. my entities' shared component never gets set.
    But using EntityQuery.ToEntityArray and then AddSharedComponent in foreach loop works perfectly.

    For the record, the query is set to filter for GridGenerationComponent(GridGenerationPhase.Expansion) and no other system changes the shared component of this chunk so the query should be delivering the same result when I execute it right this instant with approach toArray or delayed with approach withEntityQuery.

    Full code
     
    Last edited: Apr 24, 2021
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    Link is broken so I can't look at the full code, but if the short code is really what is happening, then that sounds like a bug worth reporting.
     
  3. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Thanks for reporting the broken link, I fixed it.
    I rather assume I did something wrong before jumping out and posting a bug report but I fail to see how the query version doesn't work since it's literaly the query my system runs on and does execute every frame and keeps processing the same entities.
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    I haven't looked at the rest of the project to determine this, but it is possible that some other system may be modifying the shared components of those entities prior to playback. When using the EntityQuery version of the ECB API, the EntityQuery is evaluated at playback rather than at record time. There is a record-time variant for ICD, but not ISCD.
     
  5. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Thought so but none of my other systems touch that chunk and i can see at runtime it remains the same value making my tiles endlessly spawn more tiles.