Sometimes I get the error below - how should I pass the CollisionWorld to an IJobEntity?
Thank you
InvalidOperationException: BoidSimulation.JobData.ColWorld.EntityBodyIndexMap is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
...
...
var colWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;
var job = new BoidSimulation()
{
center = ave,
ColWorld = colWorld,
boidConfig = boidConfig,
OtherAgentMoves = AgentMoveLookup
};
job.ScheduleParallel();
state.Dependency.Complete();
...
...
[BurstCompile]
public partial struct BoidSimulation : IJobEntity
{
[ReadOnly] public float2 center;
[ReadOnly] public CollisionWorld ColWorld;
[ReadOnly] public BoidConfigData boidConfig;
[ReadOnly] public ComponentLookup<AgentMove2d> OtherAgentMoves;
[BurstCompile]
void Execute([EntityIndexInQuery] int entityIndexInQuery, Entity entity, ref Boid boid, TransformAspect trans,
RefRO<AgentMove2d> agentMove)
{
var filter = new CollisionFilter() { BelongsTo = ~0u, CollidesWith = ~0u, GroupIndex = 0 };
NativeArray<DistanceHit> allHits = new NativeArray<DistanceHit>(40, Allocator.Temp);
var collector =
new IgnoreSelfAllCollector<DistanceHit>(boidConfig.NeighborRange, ref allHits, false, entity);
ColWorld.OverlapSphereCustom(trans.WorldPosition, boidConfig.NeighborRange, ref collector, filter);
...
...