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 [0.51] IJobEntity generates an extra query when used with specific query parameter

Discussion in 'Entity Component System' started by xVergilx, Oct 17, 2022.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Is there a way to avoid it?

    For example, I've got a query declared as:
    Code (CSharp):
    1.          _dealDamageStatusQuery = GetEntityQuery(ComponentType.ReadWrite<DealDamageContinuously>(),
    2.                                                  ComponentType.ReadOnly<DetectionHit>(),
    3.                                                  ComponentType.ReadOnly<TimerComponent>(),
    4.                                                  ComponentType.ReadOnly<GenerateDamage_Tag>(),
    5.                                                  ComponentType.ReadOnly<HasDetectionHits_Tag>(),
    6.                                                  ComponentType.ReadOnly<StatusOnly_Tag>());
    It is passed as parameter to the job in OnUpdate:
    Code (CSharp):
    1.          new GenerateStatusForContinuousDamageJob
    2.          {
    3.             EntityReferences = entityReferences,
    4.             Statuses = statusBuffers
    5.          }.Schedule(_dealDamageStatusQuery);
    However, actual job has less types:
    Code (CSharp):
    1.    public partial struct GenerateStatusForContinuousDamageJob : IJobEntity {
    2.       ...
    3.       public void Execute(ref DealDamageContinuously damage,
    4.                           in DynamicBuffer<DetectionHit> hits,
    5.                           in TimerComponent time,
    6.                           ref RandomData rnd) {
    7.            ...
    8.       }
    9.    }
    Which results in an extra query being added to the system, and actual job execution will be performed on components set in Execute parameters. Which ends up using all entities, ignoring tags set in EntityQuery.

    Is there a way to avoid this other than manually declaring types as parameters for Execute?
    Those are tags, and aren't used, so no point in fetching them, right?

    TL;DR: What's the equivalent for .WithAll<T> for IJobEntity?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    upload_2022-10-17_12-41-44.png

    I've missed you're on 0.51 :) But should be valid too, as all these attributes exists in 0.51
    upload_2022-10-17_12-44-35.png
     
    Last edited: Oct 17, 2022
    xVergilx likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Just realized RandomData was not included to the query.
    However, adding it didn't helped, still generated an extra query without extra parameters;

    Yep, adding types via [WithAll] works. Thanks :)
     
  4. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    This does appear to be an issue (I logged as a ticket). We do generate an extra query in the system that is not used.
    Also, it is entirely up to you to ensure that your query works with the method parameters of your job's Execute method (we are adding some validation here - but there is none currently).
     
    xVergilx likes this.