EntitySpawnAfterEvent Class
Contains data related to an entity spawning within the world.
Examples
logEntitySpawnEvents.ts
// Register a new function that is called when a new entity is created.
import { world, EntitySpawnAfterEvent } from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
const spawnLocation = entityEvent.entity.location;
world.sendMessage(
`New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`,
);
});
Properties
cause
read-only cause: EntityInitializationCause;
Initialization cause (Spawned, Born ...).
Type: EntityInitializationCause
entity
entity: Entity;
Entity that was spawned.
Type: Entity
Important
This property can't be edited in read-only mode.
Examples
logEntitySpawnEvents.ts
// Register a new function that is called when a new entity is created.
import { world, EntitySpawnAfterEvent } from '@minecraft/server';
world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
const spawnLocation = entityEvent.entity.location;
world.sendMessage(
`New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`,
);
});
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for