Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

excluding entities from filters

Discussion in 'Project Tiny' started by lulitd, Jul 26, 2019.

  1. lulitd

    lulitd

    Joined:
    Feb 20, 2016
    Posts:
    13
    Hi everyone.

    I was just wondering how to exclude entities from a query.

    Let's say I have a few entities with Components A and B, and a few entities with components A, B and C.

    I have a system that uses Components A and B. How do I prevent the system from affecting entities that also have component C?

    Would I just check if the entity has component C or is there a more correct way of excluding some entities?

    Code (JavaScript):
    1.  this.world.forEach([Entity, ComponentA, ComponentB], (entity, a, b) => {
    2. if(this.world.hasComponent(entity,ComponentC))return;
    3. // do stuff here!
    4. }
     
  2. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Last edited: Jul 26, 2019
    lulitd likes this.
  3. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    51
    You can do the following:

    Code (CSharp):
    1. Entities.WithAll<A, B>().WithNone<C>().ForEach((Entity e) =>
    2. {
    3.     // do work on entities which only have A and B components
    4. });
    Hope this helps!
    Kev
     
  4. lulitd

    lulitd

    Joined:
    Feb 20, 2016
    Posts:
    13
    Awesome! Thank you both!