LoadAssetContainerAsync on error?

Hello, when I load a model with this async function it will throw an error on a model that does not exist (403/404) is there a way to catch this error so it does not break the rest of my script?

Uncaught (in promise) RequestFileError: Error status: 403 Forbidden - Unable to load http://my-site.bla.com/storage/models/55/gltf/notexist.gltf

I could only find this real quick, I am not very familiar with promises but is there no error handler on this or does a try catch work? (I think not?)

You can load a model with the Asset container and use onSuccess and an onError callbacks:

meshTask.onError = function (task, message, exception) {
    console.log(message, exception);
}
2 Likes

Alright but the last parameter is the scene name?

I see no mention of scene name? I tried scene.name but it is undefined

This, to be exact, is not the name of the scene, but the name of new Scene instance.
So when you make Assets Manager like
var assetsManager = new BABYLON.AssetsManager(scene);

scene - is the name of the variable which you define in the beginning of createScene() function:

var scene = new BABYLON.Scene(engine);

Alright I had an error at first because I got params mixed up, but it’s doing something now thanks!

1 Like

Having been encountering a lot of issues using this asset manager. It appears to break almost everything in any scene I use it in? How does it load the model differently?

With mesh task

With LoadAssetContainerAsync

So it even manages to break my framingBehavior for some reason!? Do I need to something else to make it behave like the mesh container I was using before?

I’ve seen a lot of similar things in my own scripts and they were always solved with the code corrections. Based on screenshots it is diffucult to say where the error is; so we need Playground with example to solve this.

I was trying to set something up but it gave me an error like “cannot save your code might be too long”?
Never had this issue before I think.

Here’s the code at least, I tried to paste in the function I am using. Couldn’t get the model to load from any of the examples yet though (sometimes I also have issues with firefox?)

Here is your code - Babylon.js Playground
Boombox is there (so the model is loading successfully), but there is a problem with the camera, as it is seen in the console:

hey @efsjouw, there is a mix of mistakes,… just read the doc step by step and you’ll success.
FramingBehavior working only on ArcRotateCamera,… you createad a freeCamera


And after this you wanted to overwrite this camera with other camera, but you didn’t pass corect the parameters,(you created other freeCamera) and did not store this new created camera into your ‘camera’ variable

But you are in the right way :wink:
Cheers!
1 Like

And the pg https://playground.babylonjs.com/#KJ9NB9#1

1 Like

Mh I got it loading and changed it to arcrotate (which I was actually using in my project already) but I can’t see the boombox anymore with the meshtask?

https://playground.babylonjs.com/#KJ9NB9#2

EDIT - Okay not sure why this is but adding this fixes it for me on my project

if (scene.isLoading) {
        scene.onDataLoadedObservable.addOnce(() => prepareCamera(scene, mainCamera));
 } else {
     prepareCamera(scene, mainCamera);
 }

https://playground.babylonjs.com/#KJ9NB9#3
it is line 78, I think your arcrotateCamera has a problem

1 Like