I am getting an error when switching from 7.22.5 to 7.49

BABYLON.SceneLoader.ImportMesh which I used in version 7.22.5 and then the onMeshLoaded method I ran gives an error in version 7.49

var hallLoader = BABYLON.SceneLoader.ImportMesh(
			"",
			env.STATICS_SERVER + "/assets/babylon5/hall_yeni/",
			"hall.gltf",
			this.sahne,
			(meshes) => {
				var scale = 100;
				meshes[0].scaling = new BABYLON.Vector3(scale, scale, -1 * scale);
  }
		);
hallLoader.onMeshLoaded = (mesh) => {
console.log(mesh)
}

The error message I encountered
↓↓↓↓
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘onMeshLoaded’)

Is this local? on the playground?

If it is local, did you update the loaders package as well?

No No, local of course.
I use CDN
These packages
https://cdn.jsdelivr.net/npm/babylonjs-gui@7.49/babylon.gui.min.js
https://cdn.jsdelivr.net/npm/babylonjs@7.49/babylon.js
https://cdn.jsdelivr.net/npm/babylonjs-loaders@7.49/babylonjs.loaders.min.js

CC @ryantrem , ImportMesh returns void now. was the signature different before?

Yes, when mime type support was added, it introduced new asynchrony in previously synchronous paths, and a breaking change was made to this API: Adding support to mimetype autodetection by deltakosh · Pull Request #15798 · BabylonJS/Babylon.js

3 Likes

You can do a similar thing with newer APIs though like this:

const assetContainer = await BABYLON.LoadAssetContainerAsync("https://raw.githubusercontent.com/BabylonJS/Assets/master/meshes/ufo.glb", scene, {
    pluginOptions: {
        gltf: {
            onMeshLoaded: (mesh) => {
                console.log(`Loaded mesh: ${mesh.name}`);
            },
        },
    },
});
assetContainer.meshes.forEach((mesh) => scene.addMesh(mesh));

Here is a PG for this: Babylon.js Playground

3 Likes

Thank you very much <3