multiple physics scenes (aka moving actors between world simulations)


To make this concrete, a specific use-case I’m interested in prototyping: 2 actors in different scenes that have different gravity settings, throwing let’s say a box in between them.

I know as of v2.8 the only way to support this was to manually remove and re-insert an entity between scenes. This is really messy and I suspect not terribly performant. Does anyone know if and how Physx 3 improves the situation? How would you approach this problem?


With PhysX 3.x, you don’t need to destroy and recreate the same actor when switching between scenes of different gravity values. You can just create the object once and use PxScene::addActor to add to that scene and PxScene::removeActor to remove it. So that one actor still exists, and you can control when it will be added into a particular scene.

Or you can apply your custom gravity to individual actors through PxRigidBody::addForce, like our SampleCustomGravity does.

Thanks, that’s good news. Pondering this further… perhaps using custom gravity per-actor would indeed be better anyway. A couple follow-up questions related to that:

Is per-scene gravity simply a matter of convenience or does the engine optimize the case? i.e. as the number of entities increases does scene gravity scale better, or is it under the covers simply doing exactly what I’m doing by apply per-body gravity anyway?

Also: is the best approach to detect that an entity is entering a different gravity “region” to setup a trigger shape or should I be detecting that completely outside the physics simulation?

Thanks for the helpful response!


I would give the multiple scenes with different gravity values a try if you have thousands of actors and don’t want to apply gravity manually. PhysX has its own optimizations to handle a large number of actors. There’s also PxActorFlag::eDISABLE_GRAVITY.

It depends on the number of actors in your world. I would imagine manually looping through thousands actors to apply the same gravity force might not be ideal. But if your world is small and you want a tighter control, by own means, apply per-body gravity.

onTrigger seems like the most convenient way to detect an actor entering a field. Otherwise, you’ll have to detect that using the actor’s global pose.

I would like this to scale to many hundreds or thousands so multiple scenes it is. Thanks again for the help!