Raycast does not hit same frame Colliders even after BuildPhysicsWorld.FinalJobHandle.Complete()

@petarmHavok Thanks! However even after calling buildPhysicsWorld.FinalJobHandle.Complete() after adding the PhysicsCollider it still does only work on a later frame.

// 1. Get systems
EntityManager      em                = World.DefaultGameObjectInjectionWorld.EntityManager;
var                buildPhysicsWorld = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
ref PhysicsWorld   physicsWorld      = ref buildPhysicsWorld.PhysicsWorld;
ref CollisionWorld collisionWorld    = ref physicsWorld.CollisionWorld;

// 2. Create Entity
...

// 3. Complete BuildPhysicsWorld
buildPhysicsWorld.FinalJobHandle.Complete(); // wait until the physics world is build

// 4. Raycast via CSharp/MonoBehaviour
if(collisionWorld.CastRay(input, out hit))
... does not hit on first frame ...

// 5. Raycast via Job & dependency
JobHandle raycastJob = job.Schedule(2, 64, buildPhysicsWorld.FinalJobHandle);
raycastJob.Complete();
... does not hit on first frame ...

What bothers me, is that the job variant has the buildPhysicsWorld explicitly as dependency and therefore should run after the physics world is up to date.

Furthermore the MonoBehaviour variant does hit the back fo the collider, while the job variant does not

var forward = new RaycastInput {
Start  = new float3(0, 10,  0),
End    = new float3(0, -10, 0),
Filter = CollisionFilter.Default
};
// does hit from a MonoBevaviour and from a burstified Job
var backward = new RaycastInput {
Start = new float3(0, -10, 0),
End    = new float3(0, 10,  0),
Filter = CollisionFilter.Default
};
// does hit from a MonoBevaviour but not from a burstified Job

Seems I am running into the very same again… How to ensure Physics World is updated within the same frame? . This is really grinding my gears, it can’t be so difficult to add a collider and tell the job to run after the BuildPhysicsWorld system has updated …

It worked back then and seems not to work in 2020.1.0b9 with the new packages

"com.unity.entities": "0.10.0-preview.6",
"com.unity.jobs": "0.2.9-preview.15",
"com.unity.physics": "0.3.2-preview",
"com.unity.burst": "1.3.0-preview.13"