Search Unity

Change Filter for 3+ types?

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

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    I get the EntityQuery (
    SetChangedVersionFilter
    ) only supports up to two, so how do I manually implement checking for 3+?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Use IJobChunk and check the change version per chunk.
     
  3. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
  4. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    Ended up doing this:

    Code (CSharp):
    1.  
    2.         if (LastVersion == m_Query.GetCombinedComponentOrderVersion()) {
    3.             return inputDeps;
    4.         }
    5.         LastVersion = m_Query.GetCombinedComponentOrderVersion();
    6.         UnityEngine.Profiling.Profiler.BeginSample("ChangeTest");
    7.         NativeArray<ArchetypeChunk> nativeArrays = m_Query.CreateArchetypeChunkArray(Allocator.TempJob);
    8.         bool Changed = false;
    9.         for (int j = 0; j < nativeArrays.Length; j++) {
    10.             for (int i = 0; i < InputDynamic.Length; i++) {
    11.                 Changed |= nativeArrays[j].DidChange(InputDynamic[i], LastSystemVersion);//
    12.             }
    13.         }
    14.         nativeArrays.Dispose();
    15.         if (!Changed) {
    16.             UnityEngine.Profiling.Profiler.EndSample();
    17.             return inputDeps;
    18.         }
    19.         UnityEngine.Profiling.Profiler.EndSample();
    20.         return base.OnUpdate(inputDeps);
    ChangeTest takes about 0.10 ms. The only issue is that it does not run the first time an entity gets the needed components (decided in runtime through reflection). Not sure which part of it is wrong. I will also probably update to have nativeArrays be reused to queue jobs directly only on changed chunks later on.