Errors using a [ReadOnly] PhysicsWorld before BuildPhysicsWorld system

I need to make a system that does physics queries before BuildPhysicsWorld, which means that this system needs a job that uses a [ReadOnly] PhysicsWorld. And in my particular use case, I have good reasons not to want to run this system after the physics update

When I run it in play mode, I get this error:

(CharacterMovementSystem is my system that runs before BuildPhysicsWorld and does physics queries)

I thought maybe adding this to my CharacterMovementSystem would solve it:

…since BuildPhysicsWorld calls Complete() on EndFramePhysicsSystem’s finalHandle before it runs, but it doesn’t seem to have changed anything

Any ideas? I’d like to avoid a JobHandle.Complete() if possible

We have done some changes that will appear in the next release that help you squeeze in a job before and after a system (imagine having AddUserDependency on any of the physics systems so you can schedule a job, get a handle, and provide that handle to BuildPhysicsWorld as an input dependency). Does that sound like something that would help? It appears so…

3 Likes

Yup, that’s exactly what I need!

1 Like

Are you doing a full combine and then set back? We run our entire simulation between BuildPhysicsWorld and EndFramePhysicsSystem. You need to combine with BuildPhysicsWorld.FinalJobHandle, pass that to your job and then add the dependency your job returns to EndFramePhysicsSystem.HandlesToWaitFor.

Oh I misread you need to run before BuildPhysicsWorld. It would be possible if the setter on EndFramePhysicsSystem.FinalJobHandle wasn’t private. I swear the private stuff in this package will be the death of me…

Edit: Actually sort of a hack but if you create a job that creates a dependency BuildPhysicsSystem has like on a transform, then combine that with your physics job, that might work. Hard to know for sure without testing.

1 Like