Retrieving "Self" of an Object From Collision Pick

Quickly put, is there a way to retrieve “self” of an object? I have a picking ray set up to pick an object, but what I want to get is the instance itself, so I can store it in a variable and thus have a pointer to that instance (self).

if base.mouseWatcherNode.hasMouse():
    if MouseCtrlr.PickRayH.getNumEntries() > 0:
           pickedObj = MouseCtrlr.PickRayH.getEntry(0).getIntoNodePath();
           pickedObjx = MouseCtrlr.PickRayH.getEntry(0);
           SrfPnt = pickedObjx.getSurfacePoint(render);
           GETname = pickedObj.getNetTag("Pickable");

    if self.Keyboard["mouseL"] == "1":
        if GETname == "Cone":
              mpos = base.mouseWatcherNode.getMouse();
              MouseCtrlr.Col_Ray.setFromLens(base.camNode, mpos.getX(), mpos.getY());
              pickedObj.setPos(SrfPnt.getX(), SrfPnt.getY(), Tland.PickObj1.getZ());

Are there P3D API calls for getting “self?”

“self” refers to the instance itself, so if you have the instance, you implicitly have its “self”…

I know, but that’s not being returned by my picking ray…

What if I used -

pickedObj = MouseCtrlr.PickRayH.getEntry(0).getIntoNodePath()

Because I’m retrieving the IntoNodePath, that would probably store “self”, that is the instance, right?

This might be more clear -

I want to get this info with the picking ray:

<__main__.Actor_1a instance at 0x042d8508>

Ok, I figured out how to do it. I just simply passed the info over to the event which handles the collision detection.

One more question -

If I set a “Tag” (setTag) to an object and destroy that object, would the “Tag” memory also be cleared?

You won’t be able to destroy that object without destroying the tag first. It’s called a cyclical reference, and if you aren’t careful with them, they can cause memory leaks in your program. If you remove all references to the object, it’ll still hold a cyclical reference to itself, so it will remain in memory until you close the program, with no way for you to access it.

So how would I destroy the “Tag?”

If you applied a tag with self.setPythonTag(‘foo’, self), you can either assign the tag again to something else (like self.setPythonTag(‘foo’, None)), or you can remove it altogether with self.clearPythonTag(‘foo’).


I was using Object.setTag(). I guess I should change it to setPythonTage()…


setPythonTag() didn’t work for me; code broke. I went back to seTag, but I’m guessing it would be cleared the same way.

It’s true that setTag() and clearTag() work the same way as setPythonTag() and clearPythonTag(). But since setTag() only stores strings, there’s no possibility of a cyclical reference there, so there’s no particular need to clear the tags.