Remove NodePath on Collision?

Hello, decided to have a play with collisions and it seems straightforward but for some reason I cant get the following to sink in.

I am creating a list of model NodePaths and having them move around the screen. I created a CollisionHandlerQueue plus a CollisionTraverser and added the objects to them. On checking the queue they are generating the event needed.

I then get the NodePath and want to remove it from the scene.

entry = self.collisionQueue.getEntry(i)
objectNodePath = entry.getIntoNodePath()
objectNodePath.remove()

But when I then call my class that updates the positions of the objects, the NodePath is still active. Is it possible to call something on the objectNodePath in the checking events loop that will remove it from the sceneGraph so the NodePath reports as Empty() or something similiar?

Thanks in advance.

You are removing the NodePath that contains the CollisionNode, which is probably not the one you wanted to remove. Presumably you wanted to remove the object itself, which I assume is a parent of the CollisionNode.

The easiest way to get a handle back to the object is to use the tag system and set a tag on your object node when you create it:


myObject.setTag('object', '1')

The value of the tag doesn’t matter in this case, just the fact that it has a tag with a particular key. Then when you get the collision event back, use the findNetTag() method to return the parent with the indicated key:

entry = self.collisionQueue.getEntry(i)
objectNodePath = entry.getIntoNodePath().findNetTag('object')
objectNodePath.removeNode()

David

Thanks for the info David. I was confusing the model nodepath with the collision nodepath :blush:

I did think about using tags. I try with a naming convention and see how that pans out.

Once again, thanks for the info.