Hi ๐
I am working through the DOTS bootcamp videos and in Day 3 there is a
DynamicBuffer<Heat> HeatBuffer
We use it to store the values in a way that we can easily get access to neighbour Entities by means of calculation. But then we use it inside a job:
[WithAll(typeof(GroundCell))]
[BurstCompile]
public partial struct GroundCellUpdate : IJobEntity
{
public float ElapsedTime;
public Config Config;
[ReadOnly] public DynamicBuffer<Heat> HeatBuffer;
public float MinY;
public float MaxY;
public void Execute(ref LocalTransform trans, ref URPMaterialPropertyBaseColor color, [EntityIndexInQuery] int entityIdx)
{
var heat = HeatBuffer[entityIdx].Value;
...
color.Value = math.lerp(Config.MinHeatColor, Config.MaxHeatColor, heat);
entityIdx++;
}
}
Now as far as I understand Queries returns Entities in no particular order. So how does the [EntityIndexInQuery] int entityIdx matches the index of the var heat = HeatBuffer[entityIdx].Value; ?
Here is the code that calls the job:
DynamicBuffer<Heat> heatBuffer, Config config)
{
var minY = -(config.GroundCellYScale / 2);
var groundCellUpdateJob = new GroundCellUpdate
{
Config = config,
HeatBuffer = heatBuffer,
ElapsedTime = (float)SystemAPI.Time.ElapsedTime,
MinY = minY,
MaxY = minY + config.GroundCellYScale,
};
return groundCellUpdateJob.Schedule(dependency);
}```
I might have missed something that was said previously about it ๐
But maybe someone can explain this to me - how can we be sure that the query index matches the HeatBuffer index ?