Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / loadAssets

Function: loadAssets() ​

ts
function loadAssets(
   world, 
   sources, 
__namedParameters?): Promise<void>;

Defined in: assets/runtimeAssets.ts:285

Load files now and resolve when they're ready. A model, a texture, a sound, a .prefab (with every file inside it) or a .soundbank.json; anything else is fetched as bytes.

Paths resolve the way shipped assets do, so "assets/boss.glb" works in Preview and in a published build. Asking twice, or while an entity is loading the same file, shares one load. If some files fail the rest still finish, then this rejects with an AssetLoadError naming them, and nothing failed stays cached, so calling again retries.

Parameters ​

ParameterType
worldWorld
sources| AssetSource | AssetSource[]
__namedParametersLoadAssetsOptions

Returns ​

Promise<void>

Example ​

ts
await loadAssets(world, ["assets/level2/boss.glb"], {
  onProgress: ({ fraction }) => (bar.style.width = `${fraction * 100}%`),
});