Scene.meshes is not returning proper array when glTF loaded to the scene


scene.meshes works fine on primitive meshes that we make by BABYLON.MeshBuilder:

However, it seems that when I append scene made with glTF,

BABYLON.SceneLoader.Append(’./’, ‘untitled.gltf’, scene)

scene.meshes doesn’t return decent structured array.
You can use this sample gltf file:

Firstly :


returns array but it is nested.



returns undefined,

typeof scene.meshes

was an object, and deeper inspection, it is surely an array.

I think this is kinda bug…
Any idea?

BTW, “cannot access mesh” on the console above is my annotation

if (scene.meshes[0] === undefined) {
console.log(“cannot access meshes”)

so just forget about it.

Not a bug see warning

Using the inspector will give you the node structure for you import.

It’s not answering my question.
the warning is basically saying that there is additional mesh on top of the mesh saying root.

I want to access each mesh, for example in order to set materials, but like,


and none of the "scene.meshes. " syntax works.

Hello again,

Multiple errors here :wink: Usually, it’s always multiple errors and false interpretation that cause a crash :wink: :flight_arrival:

First, you may want to have a look at how to import external assets from dropbox. You can find this here.

Second, the function you are running is twisted. The correct form is in this pg also with a variant of the simple/base function (lines 30 to 36).

In short, it should read:

scene.meshes.forEach((m) => {
console.log (“my meshes”);

Hope this helps,

Edit, forgot to mention that by default a gltf will export all meshes in a parent node as you can see by opening ‘the inspector’ in the PG and unfold ‘nodes. So, when you call mesh[0] you are actually calling an empty node (the parent). The most common technique is to start by removing this parent. There’s a video that explains this better than I ever will :wink: I would just need to find it… OK found one, not the one is was thinking of but is nicely expained in this video for 'thin instance’. Go to minute 4:15 of the video.

Oh, I’m sorry about that.
I saw that expression on a topic on the forum.
Of course I thought it as typo, and I’ve tried

scene.meshes.forEach((m) => {
console.log (“my meshes”);


This time again it worked… :sweat_smile:
I must check my code twice, Messy typos…

Dont’ worry and don’t give up. It’s easy to miss something with js. Not as if js would give you a lot of information about what is wrong :wink: I do it all the time :crazy_face: