AssetManager07 / 12

Loading the required bundles

Control when assets load and how their results are accessed.

AssetManager registers assets, loads them and stores the results. A bundle is a named group of assets that can be loaded together.

The runPreload method in BootPreloadService.ts loads assets sequentially:

await this.sceneContext.engine.bootstrapConfigBundles(request.configBundles);
for (const bundleName of request.assetBundles) {
  await this.assets.loadBundle(bundleName);
}

This code explicitly defines the order of the groups. AssetManager limits requests through concurrency, retry and timeout settings. These settings do not make a missing asset an acceptable result.

RegisteredThe engine knows the type and address. The content may not be loaded yet.
Loadedget(id) can return the result. The consumer still checks its type.
Both stages are needed: a manifest entry and a successful load.

Scene loading

If a bundle is needed when entering a scene, list it in SceneConfig.assets:

assets: {
  bundles: ['images', 'fonts'],
  ids: ['json/layouts/scenes/game/layout.json'],
},

This is part of a scene definition. Bundle names and IDs must exist in the manifest. loadBundle rejects unknown names, so a typo is detected immediately.

load(ids) loads individual IDs. has(id) checks for a loaded result, and get(id) returns it. For JSON, we then use a decoder; for images, a standard Pixi node or TextureAssetResolver from @gamedevland/engine/renderers/pixi.

After loading, loadRequiredBundle(name) checks that every result is present. An ordinary loadBundle call does not guarantee that every file loaded: individual loader failures are handled inside the coordinator. Use loadRequiredBundle for required assets.

For required individual files, use loadRequired(ids, { signal }); loadRequiredBundle(name, { signal }) accepts the same cancellation signal. BaseScene.preload uses required loading for assets listed in SceneConfig.assets.

Leaving a scene does not clear the shared cache: the next scene may use the same files. assets.unload(id) explicitly removes an asset. Release all GLB instances first; an asset with live instances stays in the cache.

Sources ↗

Block Puzzle · BootPreloadRequestFactory.ts↗The Block Puzzle bundle list.Block Puzzle · BootPreloadService.ts↗The original runPreload method, which loads bundles sequentially.