Change the text of a Text Node in the Scene Graph Hierarchy

Hi all, this could be a noob question due to lack of understanding of the tree, but I want to create a Text Node and then attach it to a model using

textNode = TextNode("smth_TextNode")

I wish to change the text some time later. But when I come back and iterate through the model’s children using


the node in there is a generic panda3d.core.NodePath object, which doesn’t support setText() anymore. So is there a way to access a Text Node through the hierarchy?

Or more generally, if I extend the NodePath class, and insert a self-defined object into the scene graph tree, all attributes I add to the object seem to be lost when I traverse the tree. Is there a way to retrieve or keep those attributes, without having a list that stores all the original references?

Use NodePath.node() to access the source class.


As Serega said above, the TextNode is a node (a sub-class of PandaNode), not a NodePath.

Specifically, NodePaths contain nodes, and–amongst other things–describe a path through the scene-graph hierarchy to that node.

More to the point, they’re also, I believe, replaceable: the NodePath that you retrieve from the scene-graph may not be the same instance that you put in there. However, conversely, the node that it refers to should be the same, as nodes are not in this way replaceable, I believe.

Which brings me to your next question:

I’d suggest one of two things:

  1. Keep a reference to your NodePath
    • While the NodePath extracted from the scene-graph may not be the same one that you put in, a NodePath reference that you keep yourself should be fine.


  1. Extend the PandaNode class (or some sub-class thereof) instead.
    • As mentioned above, nodes are not replaced as NodePaths may be, and so your data should be safe.

Thanks for the suggestions. I can now access the text node within the tree with NodePath.node() method.

But when I try to extend the PandaNode class (or the TextNode, ModelNode, etc) and then insert them into the tree, the NodePath.node() method still returns the superclass (PandaNode, TextNode, ModelNode).

I can keep the references to the original nodes/nodePaths, which I have been doing for some of the codes. Your explanation of the NodePath and Node is very helpful for my understanding.

The scene graph is implemented in C++. The C++ scene graph classes are unaware of the Python subclass information, so this gets lost when you try to access the node through a C++ method.

You can add arbitrary Python objects on a node using Python tags, see setPythonTag/getPythonTag.

See also the page on Subclassing in the manual.

1 Like

Ah, my mistake regarding the sub-classing of PandaNode! I’d forgotten that the scene-graph was C++ only! My apologies!