Get specific loader of a SceneLoader load function

Hello! I’ve made an application with multiple scenes that can be scrolled up and down. I’ve implemented an optimization that disposes scenes that are too far above or below the current one on screen.

Problem: Because SceneLoader.ImportMeshAsync is an async operation, when the scenes are disposed, the loaders seem to still run which end up blocking the thread, causing a delay in the creation of new incoming scenes. So I want to run dispose() when that loader’s scene is disposed to abort. I know I can use the SceneLoader.OnPluginActivatedObservable to get the loader but I think it’s disposing the loader of the wrong scene, causing new scenes to not be created correctly.

So my question is: Is it possible to retrieve a specific loader from a specific scene? Or retrieve the specific loader that’s running SceneLoader.ImportMeshAsync?

would you mind sharing a repro in the PG so we can have a better view?

Sorry my application uses React to handle the behaviors I mentioned, it’s quite complex and would take quite a lot of time to convert to a similar code in PG with plain javascript :slightly_frowning_face:

I just want to know if it is currently possible to get a loader to correctly dispose it for the scene, sorry for not able to create a repro!

cc @bghgary then :wink:

This should get the right loader to dispose. We have an integration test that tests this exact scenario. If you can set up a repro, I can investigate.

@bghgary Thank you, that’s good to hear! In order to get the loader, regarding the code, do you call OnPluginActivatedObservable to get the loader before running SceneLoader.ImportMeshAsync() like this?:

SceneLoader.OnPluginActivatedObservable.addOnce(loader => {
            if (!(loader instanceof GLTFFileLoader)) return;

                () => post.isDisposed === true,
                () => {
                        'canceling loader for post at index:',
                        posts.findIndex(post => post?.id ===

        try {
            const { meshes } = await SceneLoader.ImportMeshAsync(
        } catch (e) {
            // eslint-disable-next-line no-empty

Yes, this is how you do it right now.

1 Like

@bghgary Thank you, I’ll recheck my code, there’s probably something wrong with it then.