Animation loading code stops working (code snippet inside)

Is this maybe a bug in the engine, or have I mistyped something? My code:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject 
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task 
from import Actor 
import math 
import sys

class Asset:
    def __init__(self):
    #this function does load the mesh, but the animation doesn't work.
    #the code is identical to the code in the main class, other than
    #replacing the strings with variables.
    def Load(self, path, parentNode):
        self.mesh = Actor.Actor(path,{"Rotation":path})
class Core(DirectObject):
    # Temporary task to move the camera 
    def SpinCameraTask(self, task): 
        angledegrees = task.time * 6.0 
        angleradians = angledegrees * (math.pi / 180.0)*math.sin(angleradians),-20.0*math.cos(angleradians),6), 0, 0) 
        return Task.cont 
    def __init__(self):
        self.title = OnscreenText(text="Panda3D: Tutorial - Actors",
                              style=1, fg=(1,1,1,0.5),
                              pos=(0.8,-0.95), scale = .07)

This code that’s been commented out works perfectly, the mesh animates as it’s supposed to.

        #Load the panda actor, and loop its animation 
        #self.pandaActor = Actor.Actor("content/test/earth",{"Rotation":"content/test/earth"}) 

[color=red]This code calls the class listed up top.

        # keyboard assignments
        self.accept('escape', sys.exit)

        taskMgr.add(self.SpinCameraTask, "SpinCameraTask")
        #Set the camera in a fixed position
        camera.setPosHpr(14.5, -15.4, 14, 45, -14, 0)
        base.setBackgroundColor( 0, 0, 0 )
# the bottom, root, everything starts here.
theCore = Core()

I’ve only been playing with the Panda3D engine for a little while now, but it seems to be a good fit for the project I’m working on. However, this bug’s got me stumped. Anyone have any suggestions?

One difference I see is that the working code is loading “content/test/earth” while the non-working code is loading “content/test/earth.x”. Maybe you meant to load the bam file version instead of the x file version?


No, that doesn’t make a difference. Whether it be .X or .egg, it still doesn’t work when loaded through the class. The model loads, but doesn’t animate.

Ah, I bet the problem is that you are not saving a reference to your “n” variable. Instead, you create a local “n” variable, call n.Load(), and then let n go out of scope. This means that n.mesh also goes out of scope, so the Actor stops animating, as soon as it was started.

Try using something like self.n instead.


Thanx, that was indeed the problem. It works like a charm now. I’m still learning to speak Python :blush: … I can see many more snafus like that one cropping up.