Actor modification at run time and detection of actor node

Hello All,

I’ve got two linked questions :

  1. if i get only the name of the a node , how can i check that this node
    is an Actor before calling actor features on it.
    basically, i’m provided a name , i do a render.find(name) and i need
    to safely check wether the name provided is the name of an Actor.

Only hint i have so far is to make a render.findAllMatches("+ActorNodes")
and then for each node return, check if node.getName returns the name required but it looks quite unefficient.

  1. can i safely add animations to an Actor after creation time.
    Ie i create one Actor with two animation in the constructor. Then i need to add other animations. How can i do? is there specific cautions to take like pausing current animation maybe?

Thanks before hand for any suggestions

  1. That won’t work. The problem is that ‘find’ will find the corresponding Node, and it will construct a nodepath to that node, but it won’t give you the python Actor object. What you can do, however, is this:

x = Actor(yada yada)
x.setPythonTag(“myactor”, x)

Now you just stored a pointer to the actor object in the node. It’s easy to use “getPythonTag” to retrieve that pointer.

One thing you need to be careful about, though, is that you may have just stymied the garbage collector. The actor won’t go away until the node does, the node won’t go away until the actor does. One of these objects is going to require manual deletion.

  1. you can call loadAnims at any time. You don’t need to load any anims in the constructor.

Just to be sure, setPythonTag is in the upcoming version of Panda only?

Aw, crap, you’re right. I forgot.

The good news is, I’m trying to put out a beta ASAP.

just for the interim until the new version, you can set up a dictionary on your class that contains the name of each actor and links it to the actor instance.





#now lets say you are given the name
   #do Stuff

The get function on dictionaries will try to grab the value associated with the supplied key, and return the second input variable if the key doesn’t exist. As a result, all non-actors will never reach the “do Stuff” part of the code