Re-Attaching a NodePath

Hello. Can anyone tell me how to re-attach a NodePath after the detachNode function is called?

It’s simply done in exactly the same way as you attached it in the first place. There should be nothing terribly special for a NodePath that was “detached”–it should act pretty much like a NodePath that hadn’t yet been attached at all.

So should I do:

myNodePath = base.render.attachNewNode(myNodePath)

or

myNodePath.reparentTo(base.render)

?

The latter. :slight_smile:

Then what is the former used for?

Generally speaking, I would say that it’s for attaching a node (not a NodePath) to a NodePath, and then gaining a new NodePath (that points to the original node) out of it.

NodePaths tend to be more convenient to work with than nodes, so it’s handy to get a NodePath that points to them when attaching them to the scene-graph.

For example, when creating collision-objects it’s not uncommon, I think, to manually create CollisionNodes. These by themselves aren’t NodePaths, just nodes. But one generally wants a NodePath, and so one attaches them via “attachNewNode”.

The words node and node path have now got confusing for me since I learned Panda3D :grinning:. Anyway, thanks for the clarification.

Not a problem!

As to nodes and NodePaths, I go into this a bit in my tutorial, I think–perhaps the relevant lesson will be of help to you:

1 Like

This should be in the “More panda resources” section of the panda manual!

1 Like

Thank you! :slight_smile:

As it happens, it is! It’s the first entry under “Panda3D Tutorial Series”, I believe. :slight_smile: