Checking for Asset Spawn Events
If you have actions to perform once an Asset is spawned, despawned, or fails to spawn, you can listen for the following CodeBlockEvents within your TypeScript code. For full details on listening for CodeBlockEvents, see the
Built-In Events section.
CodeBlockEvents.OnAssetSpawned
Indicates the Asset that spawned, including the spawned Entity.
- entity [Entity]: The spawned Entity.
- asset [Asset]: The underlying Asset for the spawned Entity.
CodeBlockEvents.OnAssetDespawned
Indicates the Asset that was removed, including the despawned Entity.
- entity [Entity]: The despawned Entity.
- asset [Asset]: The underlying Asset for the despawned Entity.
CodeBlockEvents.OnAssetSpawnFailed
Indicates the Asset that failed to spawn.
- asset [Asset]: The underlying Asset that failed to spawn.
this.connectCodeBlockEvent(
this.entity,
CodeBlockEvents.OnAssetSpawned,
(entity: Entity, asset: Asset) => {
// Perform an action on the spawned Entity.
});
this.connectCodeBlockEvent(
this.entity,
CodeBlockEvents.OnAssetDespawned,
(entity: Entity, asset: Asset) => {
// Perform an action on the despawned Entity.
});
this.connectCodeBlockEvent(
this.entity,
CodeBlockEvents.OnAssetSpawnFailed,
(asset: Asset) => {
// Log the asset that failed to spawn.
});