I am trying to create a archetype of 2 types (1: entity with select tag 2: ring with a UI tag) to iterate over a job.
They are separate entities that both have a transform.
If this can be done In IJobEntity
I would prefer that.
//What i'm trying to achieve.
[BurstCompile]
partial struct SelectUIJob : IJobEntity
{
void Execute(in SelectRingData data, ref LocalTransform ringtransform, /* 2nd entity*/ in SelectedEntities selectedEntities, in LocalToWorld ltw)
{
}
}
I’ve tried IJobChunk but the example in the docs appears to be for a single archetype.
var query = SystemAPI.QueryBuilder().WithAll<SelectRingData>().WithAll<LocalTransform>().AddAdditionalQuery().WithAll<LocalToWorld>().WithAll<SelectedEntities>().Build();
state.EntityManager.AddChunkComponentData(query, new TestCombineChunk());
state.Dependency = new SelectUIChunkJob
{
SelectedLTWHandle = SystemAPI.GetComponentTypeHandle<LocalToWorld>(),
RingTransformHandle = SystemAPI.GetComponentTypeHandle<LocalTransform>(),
}.ScheduleParallel(SystemAPI.QueryBuilder().WithAll<TestCombineChunk>().Build(), state.Dependency);
[BurstCompile]
partial struct SelectUIChunkJob : IJobChunk
{
public ComponentTypeHandle<LocalToWorld> SelectedLTWHandle;
public ComponentTypeHandle<LocalTransform> RingTransformHandle;
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
var SelectedLTW = chunk.GetNativeArray(ref SelectedLTWHandle);
var ringtransforms = chunk.GetNativeArray(ref RingTransformHandle);
var enumerator = new ChunkEntityEnumerator(useEnabledMask, chunkEnabledMask, chunk.Count);
while (enumerator.NextEntityIndex(out int i))
{
var ring = ringtransforms[i];
ring.Position = SelectedLTW[i].Position;
ringtransforms[i] = ring;
}
}
}