# Howto to traverse scene nodes?

**URL:** <https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514>\
**Category:** Questions\
**Created:** [September 2, 2021, 3:39pm UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514 "2021-09-02T15:39:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephane\_Ancelot](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/stephane_ancelot/32/13576_2.png) [@Stephane\_Ancelot](https://forum.babylonjs.com/u/Stephane_Ancelot)\
**Post date:** [September 2, 2021, 3:39pm UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/1 "2021-09-02T15:39:23Z")

</div>

Hi,  
Is there an existing function that traverse a whole gltf loaded scene.?  
I need to hide nodes based on their name.

Regards  
S.Ancelot

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [September 2, 2021, 4:12pm UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/2 "2021-09-02T16:12:05Z")

</div>

you can use `rootNote.getChildren()` to get a list of children, or `getChildMeshes()` to get meshes

The API:

> **[Node | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.node#getchildren)**
>
> Node is the basic class for all scene objects (Mesh, Light, Camera.) \[API\]

and

> **[Node | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.node#getchildmeshes)**
>
> Node is the basic class for all scene objects (Mesh, Light, Camera.) \[API\]

Both allow you to get the direct descendants or all of them, which can allow you to build your own tree or get all of the root’s children. You can also define a predicate to filter what node will be included.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 2, 2021, 9:23pm UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/3 "2021-09-02T21:23:51Z")

</div>

You can also traverse `scene.rootNodes` / `scene.transformNodes` / `scene.meshes` depending on your needs.

---

<div class="post-metadata">

**Author:** ![Stephane\_Ancelot](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/stephane_ancelot/32/13576_2.png) [@Stephane\_Ancelot](https://forum.babylonjs.com/u/Stephane_Ancelot)\
**Post date:** [September 3, 2021, 7:08am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/4 "2021-09-03T07:08:58Z")

</div>

Hummm… rootNodes is empty in contianerAssset !

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [September 3, 2021, 10:27am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/5 "2021-09-03T10:27:04Z")

</div>

sorry, rootNode was just an arbitraty name of, well, the root node of your model 🙂 If your model is loaded, the first mesh that is returned from loadMesh or from the assets container is usually the root node, which is the parent of all others.  
If you want to share a playground with your attempts we can explain better

---

<div class="post-metadata">

**Author:** ![Stephane\_Ancelot](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/stephane_ancelot/32/13576_2.png) [@Stephane\_Ancelot](https://forum.babylonjs.com/u/Stephane_Ancelot)\
**Post date:** [September 10, 2021, 6:44am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/6 "2021-09-10T06:44:14Z")

</div>

No, I was talking about this variable, that is empty after loading the containerasset  
[AssetContainer | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/typedoc/classes/babylon.assetcontainer#rootnodes)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [September 10, 2021, 9:57am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/7 "2021-09-10T09:57:17Z")

</div>

want to show your scene in the playground? will be easier to explain why it is empty.

---

<div class="post-metadata">

**Author:** ![grunt](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/grunt/32/32420_2.png) [@grunt](https://forum.babylonjs.com/u/grunt)\
**Post date:** [May 23, 2023, 12:42am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/8 "2023-05-23T00:42:52Z")

</div>

I haven’t found a traverse or ‘isMesh()’ method in Babylon, but this worked for me:  
BABYLON.SceneLoader.ImportMesh(“”, “assets/models/”, “Blarg.glb”, scene, function (meshes) {  
scene.createDefaultCameraOrLight(true, true, true);  
var geo  
for(geo in meshes){  
console.log(meshes[geo].name)  
}  
});  
I think this is what you are looking for.  
Then I use a switch case statement to target a particular geometry for an operation or effect.

---

<div class="post-metadata">

**Author:** ![DRLeria](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drleria/32/50928_2.png) [@DRLeria](https://forum.babylonjs.com/u/DRLeria)\
**Post date:** [May 23, 2023, 12:57am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/9 "2023-05-23T00:57:48Z")

</div>

Also if you need to look for the class you can use

**getClassName()**

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [May 23, 2023, 9:38am UTC](https://forum.babylonjs.com/t/howto-to-traverse-scene-nodes/23514/10 "2023-05-23T09:38:30Z")

</div>

small note on getClassName - it will return the exact class name, so “Mesh”, or “AbstractMesh”, or “GroundMesh”. It’s not an exact way to make sure a node is a mesh, unless you know very well what is being used in your scene.
