Is there any way for an instance to kill itself?

I have a game involving a laser object. Throughout the course of the game, one laser at a time can be fired, and the laser has the ability to reflect off certain things. The laser instance handles all it’s own movements and reflections. I would like to get rid of each laser instance after it collides (not real collisions) with an object, or after it runs out of reflections.

I’m trying to avoid continually allocating more and more memory every time a laser is created. Is there any way to have a laser instance kill itself?


Actually, “kills” is probably the wrong word. Panda nodes are reference counted, which means for all practical purposes they are garbage collected. All you have to do is remove it from the scene graph, and don’t keep a pointer to it. It will then get garbage collected.

So you have a choice - a task that calls detachNode, or a function interval that calls detachNode.