Panda Bullet

This is the underlying Bullet callback method which gets called when performing a contact test:

virtual btScalar btCollisionWorld::ContactResultCallback::addSingleResult(
    btManifoldPoint &cp,
    const btCollisionObject *colObj0,
    int partId0,
    int index0,
    const btCollisionObject *colObj1,
    int partId1,
    int index1)

Both collision objects are CONST pointers. This means that the collision objects can not be modified within this method. What I do in BulletContactResult is simply store these const pointers and return the associated Panda3D objects (i. e. BulletRigidBody), as CONST pointers.

Usually there is a reason why an API designer passes or returns const pointers or objects. Since Bullet documentation is a bit spares I can only guess why the Bullet API passes a const pointer here: because it will lead some kind of crash if a user modifies the collision objects from within the callback.

But enough of an explanation - what can be done?

(1) Your solution is probably the best way to go. Identify somehow the panda node within the scene graph, and use this node remove/add it from the world. You can do this either by giving each node a unique name, like you mentioned. Or you can set identifying ids on each node (via setPythonTag) and look up the node in a local dictionary. Maybe you are able to do some magic using NodePath’s.

(2) I could try to cast away the const-ness of the Bullet collision object, and then have you test what happens if you modify the returned node. But it is usually not a good idea to cast away const-ness. I’d prefer not to do so.