AssetLoadSuccess

View source

Event data for an asset load that completed successfully.

A AssetServer#load request produces this event after the response has been imported and stored in its typed asset pool. The event becomes readable when the typed Events<AssetLoadSuccess> resource publishes its pending batch. Failed loads publish AssetLoadFail instead.

The payload identifies the requested asset family, its reserved or reused packed pool ID, and the complete path used for the load. It does not carry the imported asset; consumers can use the event’s typeId and assetId to locate that value in the matching typed Assets pool.

Examples

import { AssetLoadSuccess, Assets } from '@wimaengine/asset'
import { Events } from '@wimaengine/event'
import { typeid } from '@wimaengine/type'

class Texture {}
const assets = new Assets(Texture)
const assetId = assets.add(new Texture()).id()
const typeId = typeid(Texture)
const path = '/textures/player.bin'
const events = new Events()

// The success event is available after the asset has been imported.
events.write(new AssetLoadSuccess(typeId, assetId, path))
events.clear()
events.each(({ data }) => {
  console.log(`Loaded ${data.path} as asset ${data.assetId}`)
})

Constructor


constructor(typeId: TypeId, assetId: AssetId, path: string)

View source

Stores the type ID, asset ID, and path supplied for a completed asset load.

Parameters

NameDescriptionDefault
typeId

Runtime ID of the loaded asset’s constructor.

—
assetId

Reserved or reused ID in the typed asset pool.

—
path

Complete path used by the load request.

—

Properties


assetId: AssetId

View source

Reserved or reused packed ID of the loaded asset in its typed pool.