Search Unity

Feedback About non-destructive filter

Discussion in 'Entity Component System' started by eterlan, Dec 25, 2019.

  1. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Hi, I found it would be really useful to provide a job, instead of ForEach, but iterate only part of it, of which reference provided by a simple NativeArray<Entity>.

    Maybe there is another way, instead of only one choice - for loop in the chunk, an entity as key container, just like ComponentDataFromEntity<ArchetypeComponentDataType>, would also work.

    This non-destructive filter should be very important if coder want to do some dynamic filtering, even sacrifice a little performance.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Probably I misunderstood what you require, but for example IJobParallelFor would work for you?
    Or you could just do simple single threaded Job, with for loop inside. You can then terminate at anytime.
     
  3. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thanks for suggestion! But the problem is how to iterate an entity array, instead of whole query, only part of the query. ComponentDataFromEntity can get data outside of one chunk, that works, but using random memory access twice, one for get chunk, another for get entity.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    If you have entity query, like group, you could do something like that, to get array of entities.
    Code (CSharp):
    1. // System
    2. EntityQuery group ;
    3. // OnCreate
    4. group = GetEntityQuery ( ... components .... ) ;
    5. // OnUpdate
    6. NativeArray <Entity> entities = group.ToEntityArray ( Allocator.TempJob ) ;
     
    vildauget likes this.
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Agreed. We are planning to add support for explicit Entity array to Entities.ForEach
     
    vildauget, thelebaron and eterlan like this.
  6. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thank you sir. I don't explain well I guess. What I need is from entity array -> do sth, not query -> do sth. The reason is I don't need all entity in that query, but part of it, and I don't want to break the archetype by adding new tag.
     
  7. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    Thank you sir, good to know this. Really like what you and your team's work, that's amazing.