How to kill/stop active tasks within assets manager?

I have an application that dynamically loads assets. Because I want to minimize the amount of downloads the user has, I use AssetsManager to asynchronously load the assets for each asset that the user requests to load.

The first loading tasks are a set of scene background elements and a main mesh model. Subsequently, if the user selects buttons in my application, new assets are loaded. These assets are other main mesh models, and not background elements.

To handle the user selecting many assets at a time and in any order the user selects them, I implemented a queueing mechanism to allow the last selected item clicked to be loaded and rendered, while other items are loaded in the background. So if there are 5 items, and the user selects 1-5 in sequential order, the last item that loads is 5 but once it’s done it’s the only one that shows in the scene. If 1-4 are selected, they load instantly because they were preloaded when the user first selected them in sequential order.

I now have the requirement to stop loading items which may have been queued to load, and to only load the last item that the user clicked on. If there are 5 items, and the user selects them in order from 1-5, I should not load items 1-4 at all and only load the 5th item. I tried to use both AssetsManager.reset and AssetsManager.removeTask in the start of the method I use to load new tasks into my queue to remove them, but neither worked.

Looking through playgrounds (and then at the source code), it looked like these methods were used for cleanup purposes and don’t actually stop the active tasks.

Is there any way to stop a currently loading task with AssetsManager? If not with AssetsManager, is there another way to do this using other loading apis?


//pseudo code
AddToQueue(){
AssetManager reset() or removeTasks(name) // to remove current tasks i've tried both

if (Check to see if we have initiated loading and loading complete)
{
    then AssetManager.addMeshTask(new task);
}
}

ping @sebavan

We do not support cancellation on AssetManager. I think the gltf loader supports cancellation, adding @bghgary to confirm.

Yes, the glTF loader can cancel loading/downloading.

Here is an example (press c to cancel)
Cancel glTF loading | Babylon.js Playground (babylonjs.com)

1 Like