Load assets with AssetManager but not add to scene

Is it possible to have a bunch of tasks in the asset manager but not have it be sent to the scene until requested. so basically the loadAsync would do its thing but just not be added to the scene.Mabey just add it to an AssetContainer instead.

Then ideally we can cherry pick what we want from the asset container.

We sorta want to pre-load/pre-cache assets up front to make the UX a bit snappier.

Yes, this is easily possible using SceneLoader.LoadAssetContainer (or LoadAssetContainerAsync). For example:

let baseUrl = 'https://example.com/'; //for base64 urls, use ''
let path = 'example_model.gltf'; //for base64 urls, use the data: url here
let container = null;
SceneLoader.LoadAssetContainer(baseUrl, path, scene, imported => {
	container = imported;
}, null, null, '.gltf');
//do other stuff

//add all to scene
container.addAllToScene();

//add a specific mesh to the scene
scene.addMesh(container.meshes[0]);

//add a material
scene.addMaterial(container.materials[0]);

Note that you should never try to use it directly like above, and instead bind it to a setTimeout or event listener, as trying to load like above will not work since loading assets can take time (even 25ms would cause it to fail)

for other stuff using the asset manager you can read the docs.

1 Like

Hi @Anupam_Das just checking in if your question has been answered

the LoadAssetContainerAsync seemed to do the trick. Actually we are using the assetContainerTask in AssetsManager. Thanks all!

3 Likes