diff --git a/game/src/main/java/com/capdevon/engine/GameObject.java b/game/src/main/java/com/capdevon/engine/GameObject.java index 40f46b8..8388a81 100644 --- a/game/src/main/java/com/capdevon/engine/GameObject.java +++ b/game/src/main/java/com/capdevon/engine/GameObject.java @@ -88,20 +88,23 @@ public static T getComponent(Spatial subtree, Class clazz /** * Returns all components of Type type in the GameObject or any of its * children using depth first search. Works recursively. - * + * * @param * @param subtree - * @param clazz + * @param type * @return */ - public static List getComponentsInChildren(Spatial subtree, Class clazz) { - List lst = new ArrayList<>(5); - subtree.breadthFirstTraversal(new SceneGraphVisitor() { + @SuppressWarnings("unchecked") + public static List getComponentsInChildren(Spatial subtree, Class type) { + List lst = new ArrayList<>(3); + subtree.depthFirstTraversal(new SceneGraphVisitor() { @Override public void visit(Spatial sp) { - T control = sp.getControl(clazz); - if (control != null) { - lst.add(control); + for (int i = 0; i < sp.getNumControls(); i++) { + T control = (T) sp.getControl(i); + if (type.isAssignableFrom(control.getClass())) { + lst.add(control); + } } } });