Hi,
I’m trying to create a basic flocking behaviour in the ECS & Job System.
However, I can’t figure out, how I can use all ComponentDatas of one type in a job.
This is my ‘Boid’ Data:
[System.Serializable]
public struct Boid : IComponentData
{
public Vector3 position;
public Vector3 direction;
}
This is my JobComponentSystem:
public class BoidSystem : JobComponentSystem
{
struct BoidCalculationJob : IJobProcessComponentData<Boid>
{
public float deltaTime;
public void Execute(ref Boid data)
{
// I WANT TO ITERATE OVER ALL BOIDS HERE TO DO CALCULATIONS BASED ON THE DATA OF OTHER BOIDS
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
Debug.Log(boidGroup.boids[0]);
var job = new BoidCalculationJob()
{
deltaTime = Time.deltaTime
};
return job.Schedule(this, 64, inputDeps);
}
}
I already tried to add a ComponentDataArray to the BoidCalculationJob struct, but however I tried it, it resulted in errors.
So, how do I pass or access all Boids to the Job?