How to avoid double loading of GLB?

I am loading different GLB files to a scene, based on user selections..(for a product configurator)..

However, sometimes an object gets loaded twice.. with the same (id and name). which is really causing issues..before loading i check if the object is already loaded, but that doesnt help… since the function is sometimes probably running twice almost at the same time.. (async is a nightmare sometimes). How can i avoid that?

You can maintain a Set of urls being loaded and preventing loading a url if it is already in the Set

In general, loading files in babylon is severely messed up.

Seems like best way is to implement some global AssetManager to track what is already loaded and what is being loaded. And behave appropriate to your task, such as returning or scheduling to return already loaded asset container.

Scene already has a list of files being loaded:

private _activeRequests: Array<IFileRequest>;

but it’s private, undocumented, and it’s not clear if request is removed when after file is just downloaded or when it is finally parsed and imported to scene.
It’s more safe to implement own tracker and wrap importMeshAsync

Are you only running a GLB loading function for a URL once, but it’s fetching the GLB twice? And you’re able to see in DevTools that it’s double fetching?

Maybe there’s something I’m unaware of, though I don’t think I’ve seen this before

its caused by the user, clicking on different buttons.. and so… since it takes a few seconds before the object is loaded… its running the same load function double…

I managed to solve the issue, by creating a array with the loaded objects.. so, its added to this array before loading, so loading double…(still have to test what happens when you Ctrl-shift-R the environment, but assume that when the objects are still there.. the array will be too.. and vice versa)