SphereCastAll on IJob

Hello
I am trying to schedule a job after the physics system runs and i want to complete it before the next frame physics runs.

How do i manage my dependencies?? i get some random crashes because something reads/writes while physics runs..

1) I want to ensure that my job runs after this frame physics is done
2) Ensure the next frame physics waits for completion of the spherecast job before it starts

Thanks!!

According to the docs the broadphase is build in the PhysicsInitializeGroup, thereafter you have the updated collision data. (Docs: https://docs.unity3d.com/Packages/com.unity.physics@1.0/manual/collision-queries.html)

If you are working with a IJob, which enables parallel execution not tied to the Unity Player Loop, you should create a clone of the CollisionWorld. You can pass the cloned CollisionWorld to the IJob and make your collision queries with it. You need to save the JobHandle of the scheduled job and call jobHandle.Complete() on the next frame before physics to ensure it is fully finished and then you can process the job results.

1 Like