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

Question Does ISystem run on inactive entities in IJobChunk?

Discussion in 'Entity Component System' started by MatanYamin, May 16, 2023.

  1. MatanYamin

    MatanYamin

    Joined:
    Feb 2, 2022
    Posts:
    109
    Hey,

    In my game I'm using some sort of entities pooling, so some of them can be inactive.

    Does the query return all entities including the disabled ones?
    And if so, how do I specify to return only active?

    Thanks!
     
    Last edited: Jun 12, 2023
  2. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    177
    From the documentation:

    Disabling components on an entity doesn't move that entity into a new archetype, but for the purposes of EntityQuery matching, the entity is treated as if it doesn't have the component. Specifically:
    • If an entity has component T disabled, it will not match queries that require component T (using WithAll<T>()).
    • If an entity has component T disabled, it will match queries that exclude component T (using WithNone<T>()).
    Most EntityQuery operations, such as ToEntityArray and CalculateEntityCount, automatically filter out entities whose enableable components would cause them not to match the query.
    To disable this filtering, use the IgnoreFilter variants of these operations, or pass the EntityQueryOptions.IgnoreComponentEnabledState at query creation time.
     
  3. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    820
    There really isn't a public concept of "inactive entities" so I think you might need to clarify or define what you mean here. An entity is nothing more than an index into components. As Rukhanka stated there are a special class of Components that are designed to be enabled/disabled without causing structural changes, but this is a different thing.

    Ultimately whether or not an entity is enable or disabled is really just a logic concern in how you set up your systems and components. Systems can be setup to only run when specific conditions are met,
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    If you're using Disabled, then no, query matching prevents system from running on those entities.
    They won't be processed unless specified via query. Same applies to the <Prefab>.

    If you're using enabled / disabled mask - then entities are filtered inside the job.
    Meaning job will be scheduled, but disabled entities inside the chunk won't be processed.
    This is due to the fact that mask can change during simulation.

    If you need to force run on disabled entities - you can specify that, as mentioned via query.


    In any case, wanted to point out that doing "pooling" with entities is usually slower than just instantiating the new one. If its for a hybrid case - you'd probably want to inverse control (MonoBehaviours controlling Entity lifecycle, not vise versa).
     
    MatanYamin likes this.