Load assets

You can use imported assets from code using the service AssetLoader which lets you get instances of an asset by name or id.

In the example below, we see how the AssetLoader is injected and used in the onInit method to get a model by name.

import { Actor, AssetLoader, BaseActor, inject } from "@hology/core/gameplay";

@Actor()
class TestActor extends BaseActor {

  assets = inject(AssetLoader)

  async onInit() {    
    const model = await this.assets.getModelByAssetName('enterNameHere')
    this.object.add(model.scene)
  }
}

Methods

getModelByAssetName(name: string): { scene, animations }

getModelByAssetId(id: string): { scene, animations }

getTextureByAssetName(name: string): Texture

getTextureByAssetId(id: string): Texture

getMaterialByAssetId(id: string): Material

Last updated