Have some Entities 0.5.0 syntax questions
So as far as I can tell with the new lambda syntax the GetEntityQuery is handled for me BUT can someone please explain to me why my TilesBufferComponent (IBufferElementData) become RW in this lambda query and why do I see bot a RW and and RO ?
The other issues im having is im only wanting to run this job when the TilesBufferComponent changes so im using WithChangeFilter(). Problems im seeing is that var eTiles = _qTiles.ToEntityArray(Allocator.TempJob); sit outside for the lambda and called every frame. What would be the best way to handle this case. Is the correct way to handle this with
if(_qTiles.CalculateEntityCount() > 0) { // Then lambda job}
protected override void OnCreate()
{
base.OnCreate();
_ecbs = EntityManager.World.GetOrCreateSystem<BeginSimulationEntityCommandBufferSystem>();
_qTiles = GetEntityQuery(typeof(TilePositionComponents),
typeof(TileConnectedTrisComponents));
//typeof(PlanetTagPlanetId));
_qTileBuffer = GetEntityQuery(ComponentType.ReadOnly<TilesBufferComponent>());
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var ecb = _ecbs.CreateCommandBuffer().ToConcurrent();
var eTiles = _qTiles.ToEntityArray(Allocator.TempJob);
var jobHandle = Entities
.ForEach((int entityInQueryIndex, in DynamicBuffer<TilesBufferComponent> buffer) =>
{
for (var i = 0; i < buffer.Length; i++)
{
var e = eTiles[i];
ecb.SetComponent(entityInQueryIndex, e, new TilePositionComponents
{
Position = new float3(
buffer[i].PositionX,
buffer[i].PositionY,
buffer[i].PositionZ)
});
}
})
.WithReadOnly(eTiles)
.WithChangeFilter<TilesBufferComponent>()
.WithName("SetTiles_JOB_TEST")
.Schedule(inputDeps);
jobHandle.Complete();
eTiles.Dispose(jobHandle);
_ecbs.AddJobHandleForProducer(jobHandle);
return default;
}
