| source |
|---|
Represents an asset in Meta Horizon Worlds. An asset is a set of objects and scripts you can store in an asset library outside of a world instance, and then spawn into the world at runtime.
export declare class Asset Assets are stored in asset libraries that you can view and manage in Desktop Editor. The SpawnController class provides a container for managing asset spawning and despsawning at runtime.
Asset spawning excels when spawning smaller sets of dynamic content, or content that needs to spawn at different locations in a world. For larger sets of static content that always spawns at the same location in the world, the world streaming API provides more optimal performance.
For information spawning and despawning assets, see the guide Introduction to Asset Spawning.
Creates an instance of Asset.
Signature
constructor(id: bigint, versionId?: bigint);Parameters
id: bigint
The ID of the asset.
versionId: bigint
(Optional) The version of the asset.
The ID of the asset.
Signature
readonly id: bigint;The version of the asset.
Signature
readonly versionId: bigint;Creates an instance of Asset with the given ID.
Signature
as<T extends Asset>(assetClass: Class<[bigint, bigint], T>): T;Parameters
assetClass: Class<[bigint, bigint], T>
The class to instantiate for this asset.
Returns
T
The new object.
Retrieves the raw content of the asset, such as a text asset.
Signature
fetchAsData(options?: Partial<FetchAsDataOptions>): Promise<AssetContentData>;Parameters
options: Partial<FetchAsDataOptions>
(Optional) The optional settings for the asset.
Returns
Promise<AssetContentData>
An AssetContentData object that stores the raw asset content and can return it in formats that are easier to use.
Remarks
Use this method to retrieve large amounts of data to populate the world. Not all assets can be parsed as data. Before calling this function, you must upload the asset to the asset library.The first time you fetch the asset content, it is loaded locally in the cache. This increases the speed of additional fetch attempts, which retrieve the data from the cache by default. In rare cases, the asset is updated outside of the world instance while the instance is running. In that case, you may want to ignore the cache and retrieve the updated data directly from the server.In the options parameter, this method provides an optional skipCache setting, which enables you to ignore the local cache when retrieving the asset content. You should not enable this feature unless the content was already updated while the world instance is live; otherwise, it will degrade the performance of your world.
Specifies data to serialize as JSON.
Signature
toJSON(): {
id: bigint;
versionId: bigint;
_hzType: string;
};Returns
{ id: bigint; versionId: bigint; _hzType: string; }
A valid object that can be serialized as JSON.
Creates a human-readable representation of the object.
Signature
toString(): string;Returns
string
A string representation of the object