Hi. I have an architype taht has two IEnableable components A and B. In a IJobEntity, i just want to query all entities with A enabled and set B to true, no matter B is originally true or not
One workaround is using a componentlookup< B> field, instead of using enableRefRW< B> parameter. But this seem inefficient. Ideally, i can ignore the state of B specifically so that i can use enableRefRW< B> as parameter and enable it in execution.
[WithAll(typeof(A))]
[SomethingLike_IgnoreEnableStateOf(typeof(B))]
partial struct MyJob: IJobEntity
{
void Execute(EnableRefRW(B) b, OtherComponents oc, ... )
{
SomeOperations( ... );
if ( someConditions )
b.ValueRW = true;
}
void SomeOperations( ... )
{
...
}
}
Hi there,
If I understood correctly, you want to build a Query
that matches Component A
present and enabled, and Component B
present (ignore enabled).
If you only need to filter the results in your Query
, but do not need access to those components, you could use the .With
methods.
// Pseudo-code
SystemAPI.Query<...>().WithAll<A>().WithPresent<B>()
Ref. WithAll<T>
Ref. WithPresent<T>
If you need to evaluate it’s state in code, check EnabledRefRO<T>
or it’s write counterpart EnabledRefRW<T>
Hope this helps 
Hi, GiantCobayo! Thank you for answering. I want to achieve this
[WithAll(typeof(A))]
[SomethingLike_IgnoreEnableStateOf(typeof(B))]
partial struct MyJob: IJobEntity
{
void Execute(EnableRefRW(B) b)
{
b.ValueRW = true;
}
}
But using (EnableRefRW(B)
as parameter would filter out those entities with B disabled. That’s what i am struggling with.
Hi, toomasio. Thanks for your reply! Sorry for making you confused. I also need to make other operation s in the Execute()
method. These operations will need to apply to those entities with B enabled. If I use [WithDisabled(type)]
, they will be excluded from the query. I have updated an example in the question. Could you look at the example again?
Gotcha! I missed the IJobEntity
part 
I believe your question was answered here
TL:DR; To read an IEnableableComponent
without filtering by its state (true / false), you can do:
[WithPresent(typeof(TestEnabled))]
public partial struct TestEnabledJob : IJobEntity {
private void Execute(EnabledRefRW<TestEnabled> testEnabled) {
testEnabled.ValueRW = !testEnabled.ValueRO;
}
}
Note: I tested this on latest
(v1.3.9
) of Entities
package and it’s working.
Yes. The WithPresent
attribute works like a charm. Thank you!