Pointers get lost for when deepcopy collisiontraverser

I am doing something like this in a function of a class

self.ctrav.addCollider(collision_nodepath, self.chan)

The collision_nodepath is a child of a self.np (NodePath()) object.

When I copy an instance of this class,
The added colliders keep pointing to the children of the old instance’s self.np.

Is there a way to get it correctly updated?

Thanks!

I think the best thing to do is to override the class’ __deepcopy__ which creates a new CollisionTraverser and adds the copied colliders.

Thanks a lot. I have another pointer pointing back to a host class, which makes things complicated… My final solution was to give up deepcopy and implemented a self.copy() function. But why deepcopy does not work for the nodepath added to the CollisionTraverser?

CollisionTraverser does not implement a __deepcopy__ method. Even if it did, it’s not obvious that a deepcopy would require it to copy the entire scene graph attached to the collider.

1 Like