Loading Actors and Animations

The Python class Actor is designed to hold an animatable model and a set of animations. Since the Actor class inherits from the NodePath class, all Common State Changes are applicable to actors.

Note, however, that Actor is a Python class that extends the C++ NodePath class. For the most part, you don’t have to think about this: Actor inherits sensibly from NodePath and generally does what you expect. There are a few subtle oddities, though. When you attach an Actor into a scene graph, the low-level C++ Panda constructs only record the NodePath part of the Actor in the scene graph, which is fine as long as you also keep a pointer to the Actor instance in your Python objects. If you let the Actor destruct, however, its visible geometry will remain, but it will cease animating (because it is no longer an Actor). Also, even if you keep the Actor object around, if you retrieve a new pointer to the Actor from the scene graph (for instance, as returned by the collision system), you will get back just an ordinary NodePath, not an Actor.

The Actor interface provides a high-level interface on the low-level Panda constructs. In Panda, the low-level node that performs the animation is called Character. You can see the Character node in the scene graph when you call actor.ls().

Do not confuse the Actor class with the ActorNode class, which is used for physics. They are completely unrelated classes with similar names.

Using Actors

The Actor class must be imported before any loading or manipulation of actors.

from direct.actor.Actor import Actor

Once this is done, the actor object can be constructed, and the model and animations can be loaded.

Loading each animation requires a dictionary, where each key is a meaningful name given to the animation and the corresponding value is the path to the animation file.

All of the above can be written as a single statement:

actor = Actor('hero.egg', {
    'walk': 'hero-walk.egg',
    'swim': 'hero-swim.egg',
})

Note that it is also possible to store the animations and model in the same file. This is preferred in some other model formats, such as glTF. In that case, just create the Actor with just the model as parameter, without specifying a separate dictionary for the animations.

When you wish to remove the actor from the scene, you need to call the cleanup() method. Note that calling removeNode() is not sufficient. This is due to the fact that Actor is a Python class containing additional data that can not be destroyed by the C++ removeNode() method.

Note

The paths used in the Actor constructor must follow Panda’s filename conventions, so a forward slash is used even on Windows. See Panda Filename Syntax for more information. Loading actors and animations utilizes the panda model path, the same as for static models.