How to load multiple assets in multiple runs?

Hi,
I need to load lots of assets, but not all at the same time.

Can I load assets like below and do that multiple times (each time with other assets off course)?

I ask this because it uses app.assets. And I’m not sure if the registry is reusable. Can you add multiple times to the registry?
(and do I need to keep the myAssets object in memory?)

    const myAssets = {
        wormholeWall: new pc.Asset('wormholeWall', 'container', {
            url: '/assets/models/wormhole/WormholeWall.glb',
        }),
        wormholeWall_wireframe: new pc.Asset('wormholeWall_wireframe', 'container', {
            url: '/assets/models/wormhole/WormholeWall.glb',
        }),
        thing: new pc.Asset('thing', 'container', {
            url: '/assets/models/div/statue.glb',
        }),
    };
    const assetListLoader = new pc.AssetListLoader(Object.values(myAssets), app.assets);
    assetListLoader.load((err, failed) => {
        if (err) {
            console.log(`assets failed to load: ${err}`);
        } else {
            console.log(`assets loaded`);
        }
    });

Hi @simmania,

Yes you can add as many assets as you like to the registry and at any time during your app load and run time.

One thing you may need to handle manually for some asset types like models/textures, if you aren’t using them in your scene at a certain point and you’d like to free up VRAM then do this for each asset:

// this will unload the asset from the GPU
asset.unload();

Just make sure before reusing that asset to reload it, that doesn’t download it again (it’s already in the browser cache), it just reuploads it to the GPU:

this.app.assets.load(asset);
1 Like