I am receiving a "
IndexOutOfRangeException: Index 1 is out of restricted IJobParallelFor range [0…0] in ReadWriteBuffer.
ReadWriteBuffers are restricted to only read & write the element at the job index. You can use double buffering strategies to avoid race conditions due to reading & writing in parallel to the same elements from a job." exception within this:
JobHandle hoverJob = Entities
.WithBurst()
.ForEach((Entity entity
, int entityInQueryIndex //Used for Concurrent ECB writing
, ref HoverSystemComponent hoverSystem
, ref PhysicsVelocity _physicsVelocity
, ref Translation translation
, in PhysicsMass _physicsMass
) =>
{
RaycastHit raycastHit = new RaycastHit();
RaycastInput rayInput = new RaycastInput
{
Start = translation.Value,
End = translation.Value - new float3(0, hoverSystem.hoverHeight, 0),
Filter = colFilter2
};
bool hit = collisionWorld.CastRay(rayInput, out raycastHit);
if (hit)
{
...
}
}).ScheduleParallel(startAfter);
and it appears to be triggered in Library/PackageCache/com.unity.physics@0.5.1-preview.2/Unity.Physics/Collision/World/Broadphase.cs:590)
which is:
RigidBody body = m_Bodies[rigidBodyIndex];
Is there any way around this to get raycast calls to work inside of parallelfor jobs ?