Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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:
    189
    Last edited: Jul 26, 2019
    lulitd likes this.
  3. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    15
    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!
     
unityunity