Hello, everyone,
I want to use aspect to turn on the DisabledComponent as a part of initializing a component.
When I use aspect inside of IJobEntity, it will automatically detect only enabledComponents.
If I use something like IgnoreComponentEnabledState, It will detect both DisabledComponent and EnabledComponent. It’s not desirable, cause DisabledComponent should be initialized only once right after being instantiated.
For example, I tried EntityQuery to Query only DisabledComponent and give it to IJobEntity like below.
But it didn’t work.
Is there way to detect only DisabledComponent with using Aspect?
[BurstCompile]
public void OnCreate(ref SystemState state)
{
random = new Random((uint)UnityEngine.Random.Range(0,int.MaxValue));
iniLifeQuery = new EntityQueryBuilder(Allocator.Temp)
.WithDisabled<Life>()
.Build(ref state);
}
[BurstCompile]
public void OnUpdate(ref SystemState state){
new InitializeLifeJob{
random = random
}.ScheduleParallel(iniLifeQuery);
}
[BurstCompile]
public partial struct InitializeLifeJob : IJobEntity {
public Random random;
public void Execute(ref IniLifeAspect iniLifeAspect)
{
iniLifeAspect.InitializeLife(random);
}
That’s a good question. There have been a lot of improvements to how you can query for specific enabled states, but not sure if querying specifically for a disabled component plus an aspect that uses that enablable component is possible. I remember asking for something similar a while back here .
Have you tried using both IgnoreComponentEnabledState AND WithDisabled? I know that seems counterintuitive, but I think it might do what you want.
Another option would be to add [Optional] to your EnabledRefRW<Life> field in your aspect. (I think that is supposed to work now. Or it should be supported soon according to this ). Then you can just use WithDisabled<Life>() in your query.
What I would really like to see is the ability to add a [WithDisabled] attribute to an EnabledRefRW field in the aspect so that the caller doesn’t have to specific that in the query.