#[Error] RequireMatchingQueriesForUpdate Attribute

1 messages · Page 1 of 1 (latest)

restive grove
#
[RequireMatchingQueriesForUpdate]
    [BurstCompile]
    public partial struct MySystem : ISystem
    {
        [BurstCompile]
        public void OnCreate(ref SystemState state) { }

        [BurstCompile]
        public void OnDestroy(ref SystemState state) { }

        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {
            var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
            var ecb          = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter();

            new MyJob() { Ecb = ecb }.ScheduleParallel();
        }
    }

RequireMatchingQueriesForUpdate Attribute doesn't work as expected. Event if MyJob doesn't match any entity, MySystem still call Update function. And a new command buffer would be created every frame without doing anything. How can I avoid this?

sweet copper
restive grove
#

oh, so this attribute is useless if I get ecb system singleton in my system right?

zealous tartan
#

yes

#

you would need to do state.RequireForUpdate(query)

#

to only care about the myjob query

restive grove
#

got it, I don't know about this info so I used it in all my systems 🫣 And got performance issue

#

Thank a lot

zealous tartan
#

probably one of the contributing factors (apart from user confusion) as to why they switched the default behaviour from 0.51 to 1.0

restive grove
#

What is the best practice of using Ecb system in ISystem? do you know? to avoid create a empty entity command buffer each frame

#

or the only way is to use state.RequireForUpdate(query)

zealous tartan
#

ok so this is more of an editor problem

#

it's like 5-10x faster to dispose this in a build

#

(personally i just try to avoid making structure changes and using ecbs though)

restive grove
#

got it, I think I need to review my systems because I use ecbs and modify entity a lot

#

thank for your information

zealous tartan
#

but yeah, go profile a build and make sure it's an actual issue

#

before you start refactoring everything

#

(though obviously limiting structural changes is always good)