Move child nodes


Is it possible to remove all child nodes of my first node, replacing them all with the child nodes of my second node?
I’ve tried this:


But removeNode marks my node as invalid, and thus copyTo spews out an AssertionError. Also, I don’t know whether this makes sure my main nodepath’s properties stay like they were.

Thanks in advance,

Um, not entirely sure what you’re asking for.

First, you should know that self.removeNode() will detach a node from a scene graph and then declare that NodePath invalid. But self.detachNode() will do the same thing, except that it doesn’t declare the NodePath invalid. So you could have just used detachNode() instead of removeNode().

But that doesn’t sound like what you were asking for. That would just end up with your node an orphan, and with an additional child of your node. Maybe you meant to do something like this:


But that takes the children away from other. If you want to copy them instead, you could do this:

for node in other.getChildren().asList():

Or this:



I guess you have been exposed too long to C++, welcome back to Python !
To remove children, there is NodePath.removeChildren, it’s an extension in
Or use PandaNode’s :

and there is also :

Ah, thanks a lot! I was only lookin’ at NodePath functions and not at PandaNode functions. I’ve also found copy_children there which was also really useful!
It’s actually for PGMM (in C++), but I was experimenting a bit with it first on the python shell. :wink: