Downcasting problem with Actors

here’s the problem:
I create an actor, act, with all of the animations,and what not and reparent it to another nodepath, npath

when i later iterate over the children of npath, when I should be getting an Actor back, I get a regular nodepath back.

Im trying not to explicitly store the original actor, act, in my data structure. It looks like all the information about animation is stored in act’s nodepath and not in act’s node. is there anyway to bundle this information with the node, or to not have panda downcast act?

Panda doesn’t store Python structures in its scene graph; it only stores actual nodes. It doesn’t know that the NodePath you give it has actually been extended in Python to be an Actor. So when you store an Actor in the scene graph, Panda only stores the NodePath part of it.

So you do need to store the Actor separately. If you really insist on storing it in the scene graph, you can do something like this:


actor.setPythonTag('self', actor)

and then when you do some Panda operation that finds the NodePath in the scene graph again, you would do:
actor = nodePath.getPythonTag(‘self’)
to get your Actor back. This works because the setPythonTag object allows you to associate any arbitrary Python object with any arbitrary NodePath, including associating the Python-extended Actor object with itself.

However, you have to be careful when you do a trick like this, because you have created a circular reference count: the Actor references its NodePath, and the NodePath has a PythonTag that references the Actor again. So these objects will never be deleted unless you explicitly break the chain by, e.g., actor.clearPythonTag(‘self’).

David

thanks for the help