Updating physics world whilst timeScale / fixedDeltaTime is 0

Hey everyone!

So I’ve got a scene with various dynamic objects and static objects with colliders. At runtime you can select objects with raycasts and move them using custom tools, only the static objects can be moved.

I got a time control option which sets the timeScale + fixedDeltaTime to 0 to stop all dynamic objects from moving, but obviously when the time is stopped all the systems stop too. This results into being able to move the static objects once (using the tools), but their colliders remain at their old position. So trying to select them with the raycasts only works if you click at their original position.

This same issue persists when I instantiate an entity with a collider, the entity is being made and visible in the entity debugger window, but the collision isnt build.

Is there a way to manually update the physics world for example everytime I move an object?
I’ve tried calling World.GetOrCreateSystem().Update() but that didn’t do the trick.

Thanks in advance!

The colliders should be moved but if you are firing a raycast through the PhysicsWorld then it sounds like you need to update the broadphase e.g.

myPhysicsWorld.CollisionWorld.BuildBroadphase(ref myPhysicsWorld, TimeStep, Gravity);

The SingleThreadPhysics test calls this directly.

Hmm that didn’t seem to have any effect unfortunately.
This is what i’m using at the moment, with the raycast being fired after this. (In a normal Monobehavior script, fired when clicking)

var physicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem<Unity.Physics.Systems.BuildPhysicsWorld>();

physicsWorldSystem.PhysicsWorld.CollisionWorld.BuildBroadphase(ref physicsWorldSystem.PhysicsWorld, Time.deltaTime, Physics.gravity);

Firing the raycast in the original position lets me select it, but directly clicking on the visual after moving it doesn’t. I’m using the EntityManager in a normal Monobehavior script to move the collider entities. (They’re attached to a normal GameObject which acts as the visual)

So 'm using

manager.SetComponentData(entity, new Translation { Value = (new value which i've omitted for it's size)});

This part is being called properly, and the Translation values move in the Entity Debugger window, but it could be that perhaps?

Edit: added picture of broadphase debug & collider debug


Setting Translation is the right thing to do, but it’s not enough. In addition to ECS components (Translation), you need to update the PhysicsWorld. That’s a part of what BuildPhysicsWorld.OnUpdate() does, but you can also build the PhysicsWorld on your own, as shown in “Build the world” section of SingleThreadedPhysicsSystem.OnUpdate(). Then you can build the broadphase and expect casts to hit new collider positions.

1 Like

Thanks! I did try the BuildPhysicsWorld.OnUpdate() but without building the broadphase, and later with @steveeHavok 's post just the broadphase but never together.

Just tested it and it seems to work as expected :)! Thanks again

1 Like