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

1 Like

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