Very commonly, games developers will want to be able to get a reference to the objects that have collided so they can modify some attribute of one or the other, such as a character taking damage when they are hit by an attack. In Panda3D, we can easily get the From and Into CollisionNodes from the collision entry with getFromNodePath and getIntoNodePath.

But, that doesn't give us the class instance that actually owns the CollisionNode. For that, we need to attach a reference to the class instance to the CollisionNode using PythonTags.

A PythonTag is a way to attach a reference of one thing to another. We use setPythonTag to create them.

To get the contents of the PythonTag, use getPythonTag.

A PythonTag can contain any Python object in it. Strings, numbers, class instances, anything goes.

Note that using PythonTags can cause a circular reference. For example, if we have a class instance that owns a CollisionNode and we attach a reference to that class instance to the CollisionNode, the class instance now has a reference to itself. Python will only garbage collect objects that have no references to them, so as long as the class instance has a reference to itself, it won't be garbage collected. We'll talk about this more when we discuss garbage collection in Chapter 12.