#[WithChangeFilter] and IJobEntity don't work when there is an aspect

1 messages · Page 1 of 1 (latest)

covert mesa
#
        public readonly partial struct EffectActiveChangedAspect : IAspect
        {
            private readonly RefRO<EffectActive> effectActive;
        }

        [BurstCompile]
        [WithChangeFilter(typeof(EffectActive))]
        private partial struct ToggleTagsJob : IJobEntity
        {
            private void Execute(in DynamicBuffer<EffectTag> effectTag, EffectActiveChangedAspect effectActiveChanged)
            {
                // Executes every frame even though EffectActive not changed
            }
        }```
if I change it to manually use a query with a change filter, it no longer executes every frame
```cs
            this.query = SystemAPI.QueryBuilder().WithAll<EffectActive, EffectTag>().Build();
            this.query.SetChangedVersionFilter(ComponentType.ReadOnly<EffectActive>());```
#

original

#

manually specifying query

#

looking at source gen

#
    void __AssignQueries(ref global::Unity.Entities.SystemState state)
    {
        
        DefaultQuery = new Unity.Entities.EntityQueryBuilder(Unity.Collections.Allocator.Temp)
.WithAll<global::BovineLabs.Effects.Data.Actions.EffectTag>()
.WithAll<global::BovineLabs.Effects.Data.EffectActive>()
.WithAspect<global::BovineLabs.Effects.Aspects.EffectActiveChangedAspect>()
.Build(ref state);

        
    }```
#

it just completely ignores the changefilter

#

if I remove the aspect and just use the underlying component

    void __AssignQueries(ref global::Unity.Entities.SystemState state)
    {
        
        DefaultQuery = state.GetEntityQuery
                    (
                        new Unity.Entities.EntityQueryDesc
                        {
                            All = new Unity.Entities.ComponentType[] {Unity.Entities.ComponentType.ReadOnly<global::BovineLabs.Effects.Data.Actions.EffectTag>(),
Unity.Entities.ComponentType.ReadWrite<global::BovineLabs.Effects.Data.EffectActive>()},
                            Any = new Unity.Entities.ComponentType[] {
                                
                            },
                            None = new Unity.Entities.ComponentType[] {
                                
                            },
                            Disabled = new Unity.Entities.ComponentType[] {
                                
                            },
                            Absent = new Unity.Entities.ComponentType[] {
                                
                            },
                            Options =
                                Unity.Entities.EntityQueryOptions.Default
                        }
                    );DefaultQuery.SetChangedVersionFilter(new ComponentType[1]
                    {
                        Unity.Entities.ComponentType.ReadOnly<global::BovineLabs.Effects.Data.EffectActive>()
                    });
        
    }```
it now applies the changefilter correctly
#

@ember comet maybe (or at least you might know who!)

#

(i find it interesting one uses EntityQueryBuilder, the other doesn't)

ember comet
#

Ugh! Thx for reporting it, and yeah I'm sadly aware of the descriprency between how SourceGen builds queries, tho I wasn't aware of any bugs, we'll look into it 😅

covert mesa
#

@ember comet
another broken case

        [WithChangeFilter(typeof(AbilityOnCooldown))]
        [WithDisabled(typeof(AbilityOnCooldown))]
        private partial struct AbilityDeactivateJob : IJobEntity```
#

EntityQueryDescValidationException: EntityQuery contains a filter with duplicate component type name AbilityOnCooldown. Queries can only contain a single component of a given type in a filter.
and just to confirm, it does work fine when using a query builder instead

this.query = SystemAPI.QueryBuilder().WithAll<AbilityActive>().WithDisabled<AbilityOnCooldown>().Build();
this.query.AddChangedVersionFilter(ComponentType.ReadOnly<AbilityOnCooldown>());```
ember comet
#

Oh no 😆

severe walrus
#

is there any issue tracker for this bug?

covert mesa
#

Dani on holidays (i think)

severe walrus
#

I can add

foreach (var animation in SystemAPI
                         .Query<RefRW<JellyAnimation>>()
                         .WithNone<IsAnimated>()
                         .WithChangeFilter<IsAnimated>()
                    )
            {
                animation.ValueRW.currentAnimationTime = 0;
            }```
as another broken case
covert mesa
#

not sure you can work around the Query version

#

IJE can be worked around by just passing in your own query though

severe walrus
#

as for now I just used IsAnimated state in a if

covert mesa
#

(why's this not a job/ije anyway?)

#

(or was this just a simple example)

severe walrus
#

there are like 5 entities at most which will trigger this so I assumed I could optimize scheduling cost away

covert mesa
#

personally i've never really found a case where a sync point is faster than schedule

#

maybe if you have a whole bunch of them

#

you could use ije.run i guess as an alternate workaround

severe walrus
covert mesa
#

this is the auto generated query

#

which is what is broken in IJE/and your Query case

#

WithChangeFilter is also adding the component to WithAll<>

#

even if it was added elsewhere (i.e. WithNone)

severe walrus
#

I meant the bottom part

covert mesa
#

oh yeah

#

this.query part

#

if i pass that into the IJE it works fine

severe walrus
#

ok, then I try this