Hello. I want to copy an Actor using this code:
myActor = Actor('some_model.egg', {'animation_1': 'some_animation.egg'})
copiedActor = myActor.copyTo(myNodePath)
However, copiedActor
looses all its Actor functionality (e.g. copiedActor.play
)
How do I copy an Actor with the returned result still an Actor but not a NodePath?
Based on the manual, it looks like Actor has a “copyActor” method, which may do what you want.
Thanks for your reply. Based on my understanding, copyActor copies the actor passed in the first argument to the actor self. However, I want to copy the actor self to a nodepath. How do I do that?
One way or another, a new Actor object (or one that you’re going to copy over) is called for, I daresay–a non-Actor NodePath can’t suddenly become an Actor, as far as I’m aware. (Actor and NodePath being two separate classes–specifically, Actor being a sub-class of NodePath.)
So, I would say to create the target Actor first, attach it to the desired NodePath, and then call “copyActor” from the target Actor.
Something like this:
# Given a NodePath that we want to copy to, called "targetNP",
# and an Actor that we want to copy, called "originalActor"
self.newActor = Actor()
self.newActor.reparentTo(targetNP)
self.newActor.copyActor(originalActor)
If you want the new Actor to replace the old NodePath, then you could perhaps do so by making a new Actor, attaching it to the old NodePath’s parent, copying the old NodePath’s transform to it (as well as any other properties that you may way), and then removing the old NodePath.
Something like this:
# Given a NodePath that we want to copy to, called "targetNP",
# and an Actor that we want to copy, called "originalActor"
self.newActor = Actor()
self.newActor.reparentTo(targetNP.getParent())
self.newActor.setPos(targetNP.getPos())
# (Or perhaps use "getMat()" and "setMat()" to copy the entire transform)
targetNP.removeNode()
self.newActor.copyActor(originalActor)
Ohhhh… I did not think of that! Thanks for your reply. I will try it later.
1 Like
It works! Thanks for your suggestion!
1 Like