Multiple instances of an actor animation not playing?

When loading the same actor multiple times, I can’t seem to get any actor other than the first instance to animate. In this short example code, I expect both pandas to enter the walk cycle, but only the first panda animates.

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

base.cam.setPos( -10, -10, 10 )
base.cam.lookAt( 0, 0, 0 )

pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"} )
pandaActor.setScale(0.005, 0.005, 0.005)
pandaActor.setPos( 0, 0, 0 )
pandaActor.loop("walk")
pandaActor.reparentTo(render)
print id( pandaActor )

pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"} )
pandaActor.setScale(0.005, 0.005, 0.005)
pandaActor.setPos( 0, 3, 0 )
pandaActor.loop("walk")
pandaActor.reparentTo(render)
print id( pandaActor )

run()

It’s because the second time you assign something to pandaActor, which is the same variable you used for the first Actor, you are inadvertently deleting the first Actor (because it no longer has any variables keeping it around).

The Actor’s geometry is still there and it’s still visible because you attached it to the scene graph, but the Python part of it is now gone. And when the Python part goes away, it takes its animations with it.

Assign the second actor to pandaActor2 or something like that instead.

David

Ah! Tricky! Got it. Thanks David.