#ParamSet and disjoint queries

22 messages · Page 1 of 1 (latest)

steel plinth
#

https://docs.rs/bevy/latest/bevy/ecs/system/struct.ParamSet.html#examples

I looked at this example which shows you can do

    mut set: ParamSet<(
        Query<&mut Health, With<Enemy>>,
        Query<&mut Health, With<Ally>>,
    )>

and access these via p0() and p1() etc. without having problems with joint access which you would get if you use separate Query args to the system.

However, I have a longer list of queries and I'm not a super-fan of p0(), p1(), p2() etc. so I did a #[derive(SystemParam)] instead, hoping I could splat the ParamSet queries into named fields on the struct.

This gives similar issues as when using separate queries.

Is what I'm trying not supported in any way?

magic nova
#

You can use Without filters to force these queries to be disjoint

#

Or you can use Has<Enemy> etc in your query and then match in the code

magic nova
steel plinth
#

I have a list of 6 queries, would each query need to have one With<M0>, and 5 (Without<M1>, Without<M2>, ...)?

#

Haven't look at Has<_> yet, possibly a runtime match sounds better

calm marten
#

That depends on what you're doing with the components

#

You only need these Withouts where the queries were already disjunct, to essentially convince the borrow checker that they are

#

but the borrow checker only cares if you're accessing the same component, in an overlapping way, with at least one of those mutable

magic nova
calm marten
#

Maybe one day we can tell Bevy things like x and y are never on the same entity and it'll enforce it and allow these queries

#

k that's what the link is

steel plinth
#

I see this strategy works but isn't fun to write for more entries 🤔
If I could just have named fields in the ParamSet it would be a bit better

calm marten
#

wouldn't surprise me if we end up with named archetypes that we use in with filters

#

not that it's a huge difference but technically they don't all need the withouts

#

like in the original example only one needs to without the other

#

are you actually mutating floors, checkerboards and lucky cats all in one system btw?

waxen lotus
calm marten
#

It sounds nice but I don't think that's actually the solution here, because there isn't actually conflicting access

waxen lotus