Node descendantMatches should return parent node as well

I use this code to loop through a node and get all of the children.

for (Spatial spatial : mynode.descendantMatches(Spatial.class, null)) {

 }

Recently I realized this does’t return the mynode itself. It gets the children as it should but it would be much more convenient if the first node returned was mynode then it looped through the children. If you have something you are looking for in mynode you will have to perform a separate check. It would make more sense to return all nodes including the parent node itself.

But then the name wouldn’t be right any more… since by definition the node is not its descendant.

Perhaps you really want to use a scene graph visitor. It will ultimately be executing much less code to give you the same results.

I’ve never even heard of that. I did find one brief example in the built in documentation. I’ll test it out.

1 Like