Switch from a Rigid Static to a Rigid Dynamic at runtime ?

Is this possible ?

I need to change my objects from static to dynamic bodies at runtime.

A code snippet or general directions are much appreciated :)

Have you tried making it a kinematic actor and later turning it off?

PxRigidDynamic *dyn = actor->isRigidDynamic();
if (dyn)
{
    dyn->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, isKinematic);
}

I guess that would work, but aren’t there some optimizations PhysX does to static objects ?

I’m guessing this wouldn’t be as efficient ?

Yes, I believe there are optimizations for static actors, but there are also (different) optimizations for kinematic actors. I’m not sure which is faster (it’s probably dependent on your scene). I’ve used this technique before and haven’t noticed any bad behavior.

The only other thing I can think of is to create the new dynamic actor with the data from the static actor before removing it. Essentially do the swap by removing the static actor and replacing it with a new similar dynamic actor. Yes, it’s a lot more work, but it’s probably “more correct.” This might require physx to rebuild all/part of the spatial partitioning structure; I don’t know for sure.

Good luck

PxRigidDynamic* aPlane = mScene->getPhysics().createRigidDynamic(PxTransform(PxVec3(0, -20, 0), PxQuat(Ogre::Math::PI/2, PxVec3(0, 0, 1))));
		PxShape* shape = aPlane->createShape(PxPlaneGeometry(), *mCore->getPhysicsSystem()->getDefaultPxMaterial());
		aPlane->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);
		mScene->addActor(*aPlane);

The above code creates a proper plane, but the collision doesn’t work. I’m not sure what’s wrong.

Check out the Kinematic triangle meshes (planes, heighfields) in the doc.

It is possible to create a kinematic PxRigidDynamic which can have a triangle mesh (plane, heighfield) shape. If this shape has a simulation shape flag, this actor must stay kinematic. If you change the flag to not simulated, you can switch even the kinematic flag.

Try to switch your aPlane to kinematic first before adding the plane shape.