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:
MouseCtrlr.PickRayH.sortEntries()
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());
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.
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’).
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.