Spatial to Node

I want to get the childs of a Node, but theres only a method that gives me a spatial arraylist, and spatials dont seem to have a getchildren method.

I tried to cast the spatials from the list to node, but I get this exception:

Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: com.jme3.scene.Geometry cannot be cast to com.jme3.scene.Node

when I use this loop:

for(Spatial spatial:child.getChildren())

{

children.add((com.jme3.scene.Node)spatial);

}



what should I do to get the spatials children?

If you only want nodes then do

[java]

if(spatial instanceof Node) {

children.add((com.jme3.scene.Node)spatial);

}

[/java]

Also, SceneGraphVisitor might be useful for you too http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/visitor-for-scene-graph/.