Actor and the scenegraph

I have put actors into the scenegraph and would like to then pull them out to change their animation. However, it looks as if they are not stored as Actors in the scenegraph but as characters…Is there a way to do this? I am using 1.5.4.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.actor.Actor import Actor

a = Actor('panda-model',{'run':'panda-walk'})
np = NodePath(PandaNode('Hello'))
np.setScale(.01)
np.reparentTo(render)
a.reparentTo(np)

node = render.find('**/Hello').getChild(0)
print a
print node
print node.node()
try:
	node.loop('run')
except:
	print 'not an actor :('

base.startDirect()
base.disableMouse()
base.camera.setPos(-50,0,0)
base.camera.lookAt(node)
run()

(as a sidenote, searching the scenegraph with render.find(**/+Actor) returns an error of Actor not being a class…)

One of the many disadvantages of Actor being a Python class.
Try setting the actor object as tag:

a.setPythonTag("actor", a)

When you have just a NodePath later on, you can then retrieve the actor like this:

a = node.getPythonTag("actor")

Use getNetPythonTag when you have a more complicated situation (like with collision entries)

By setting a.setPythonTag(“actor”,a), does this create a circular dependency? Do I have to be careful about deleting it then? What is the relationship between the nodepath+character and the actor?

The NodePath holds a reference to the underlying Character. There can thus be multiple NodePaths referencing the same Character - the Actor class is a class that derives from NodePath.

It indeed creates a circular dependency (thats why its actually not great that Actor derives from NodePath). You could also store a dictionary somewhere to solve this, I guess, or you just have to be extra careful (and be sure to clear the tag once you’re done with it).

(See also this thread discourse.panda3d.org/viewtopic.php?t=5550)

Is there a way to copy actors from the scenegraph? node.copyTo(render) doesn’t work…as expected, but is there a way to do it?

It depends on what you mean by copying. node.copyTo(render) should work just fine, if all you want is to copy the vertices and polygons. If you want to make another Actor that you can animate independently, use the Actor copy constructor: newActor = Actor(oldActor).

David