Is there a way to check if a node is in the scenegraph?


Is there a way to check if a node or spatial is in the scenegraph?

I mean, a Spatial can be attached to a Node that isn't attached to the rootnode.  Is there a way to check if it is?

You can ask for it by name using getChild (which is recursive)

Do you mean calling getChild on the rootNode?

Well, I don't have access to the rootNode from where I need to know it. + nodes can have the same name, can't they?

is there another way?

You could write a recursive method in your own code that uses the getParent method in Spatial to walk up the scenegraph from your spatial looking for either null (false) or the node you wish to find (true).

getParent()==null only means that it doesn't have a parent, right?

It's most likely that there will be nodes that are orphans without being the rootNode.

For now, I'm doing like you say, walking up to the rootNode + checking if getName().equals("rootNode"),

but it's not certain that the rootNode will be named like that in every app.

thanks btw.