[SOLVED] Confused using AssetListLoader

According the reference manual, AssetListLoader needs an array:

const assets = [
     new Asset('model', 'container', { url: `http://example.com/asset.glb` }),
     new Asset('styling', 'css', { url: `http://example.com/asset.css` })
 ];
 const assetListLoader = new AssetListLoader(assets, app.assets);
 assetListLoader.load((err, failed) => {
     if (err) {
         console.error(`${failed.length} assets failed to load`);
     } else {
         console.log(`${assets.length} assets loaded`);
    }
 });

But in one of the engine only examples I see that on Object is used as input:


    const assets = {
        helipad: new pc.Asset(
            "helipad-env-atlas",
            "texture",
            { url: "/static/assets/cubemaps/helipad-env-atlas.png" },
            { type: pc.TEXTURETYPE_RGBP }
        ),
        statue: new pc.Asset("statue", "container", {
            url: "/static/assets/models/statue.glb",
        }),
        cube: new pc.Asset("cube", "container", {
            url: "/static/assets/models/playcanvas-cube.glb",
        }),
    };
  ....
    const assetListLoader = new pc.AssetListLoader(
        Object.values(assets),
        app.assets
    );

What is the correct way?

Hi @simmania,

In the second case it’s still passed to the method as an array. This line returns an array with values derived from the properties of the object:

Object.values(assets)
2 Likes