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

Bug RequireOnUpdate + SharedComponentFilter not working ?

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

  1. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Probably, I'm missing something here but here is my system
    Code (CSharp):
    1. public class TestSystem : SystemBase
    2.     {
    3.         private EntityQuery _query;
    4.  
    5.         protected override void OnCreate()
    6.         {
    7.             _query = GetEntityQuery(
    8.                 ComponentType.ReadWrite<SomeComponent>(),
    9.                 ComponentType.ReadWrite<SomeSharedComponent>()
    10.             );
    11.             _query.SetSharedComponentFilter(
    12.                 new SomeSharedComponent(0)
    13.             );
    14.             RequireForUpdate(_query);
    15.         }
    16.  
    17.         protected override void OnUpdate()
    18.         {
    19.             var entityCount = _query.CalculateEntityCount();
    20.             Debug.Log(entityCount);
    21.             EntityManager.SetSharedComponentData(_query, new SomeSharedComponent(1));
    22.          }
    23. }
    My understanding is that the OnUpdate function gets called once then all the entities in the query get their shared component set to 1 making the query empty and preventing further calls to Update but I see the Debug.Log(entityCount) keep printing 0s.

    I suspect it might be that it's because the query does have entities in it before the shared component filter is accounted for ? But honestly I have no clue.

    if anyone has some insight ?
     
    Lukas_Kastern likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    If I recall correctly, RequireForUpdate ignores filtering.
     
  3. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Makes sense.
    Feels unintuitive though, kinda wish it did.
    But I guess just returning on entityCount == 0 works
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    There's also EntityQuery.IsEmpty, which is a bit faster for the fast exit.
     
  5. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Cool ! Thanks ^^