Skip to content

Spawn Point

Updated

Marks where the player enters the scene. With several, one is picked by priority each time the player joins.

Type
ent-spawn-point
Script class
SpawnPointEntity

A Spawn Point marks where the player enters a scene. When a scene loads in play, the runtime picks one of the active spawn points and places the player on it, facing the way the spawn point faces. In the editor it is only a marker: a start pad, a flag and an arrow on the ground that shows the facing. It never moves anything while you edit.

What it moves is the player’s view: the main camera, or the character that camera follows. When the camera follows a character, the character lands on the point and the camera comes along; otherwise the camera stands there at eye height. In an immersive session it places the player rig, and that placement becomes the home the XR Origin recenters to.

A spawn point only acts on arrival. To move the player during play, use a Spot Point (click to go there), a Travel Point (a portal), or the Teleport component.

The props that matter most:

  • The entity’s rotation sets the facing. The player looks along the spawn point’s forward (-Z), flattened onto the ground.
  • priority is the weight in the draw when the scene has several spawn points, from 0.1 to 1. A point at 1 is ten times more likely to be chosen than one at 0.1.
  • slots is how many places players start on: the point itself and the rest on rings around it. With 1, everyone lands on the point.
  • radius is the area, in metres, over which those slots are spread. It scales with the entity.

Each joining player takes the slot numbered by how many players are already in the room, so newcomers do not land inside each other. Offline, the player always takes the point itself.

  1. Add a Spawn Point entity to the scene where players should arrive. See Scenes and hierarchy.
  2. Rotate it so its arrow points where players should look first.
  3. For a multiplayer room, raise slots and set radius so the ring of slots fits on flat, clear ground.
  4. For several entrances, add more spawn points and give each a priority.
  5. To react from a script when it places the player, add a Signal Emitter to the spawn point and give it a signal name.

Write the name of the chosen spawn point on a UI label when the player is placed.

ArrivalLabel.jx
#pragma lifecycle(startup)
function startup() {
// Every spawn point has a Signal Emitter with the signal 'spawn'.
// 'Location' is a UI Label entity.
const label = findEntity('Location')?.getComponent(UILabelComponent);
on('spawn', (event) => {
if (event.eventType !== EventType.SpawnPoint.Place) return;
const point = findEntity(event.entityId);
const where = point ? point.name : 'the world';
if (label) label.setProps({ text: `Welcome to ${where}` });
log('Placed at', event.data.position, 'facing', event.data.rotationY);
});
}

How it works:

  • All spawn points share one signal, so a single listener hears whichever one the draw picked.
  • EventType.SpawnPoint.Place is sent once the player is placed. event.data.position is where the view was put, and event.data.rotationY is the yaw, in radians, of the spawn direction.
  • event.entityId identifies the spawn point; findEntity turns it back into the entity, whose name becomes the message. Name spawn points after their area (“North Gate”, “Harbour”) and the label reads naturally.

List every spawn point in the scene with its chance of being chosen, to tune priority values while you build.

SpawnOdds.jx
#pragma lifecycle(startup)
function startup() {
const points = [];
scene.entities.forEach((entity) => {
if (entity instanceof SpawnPointEntity && entity.isEnabled()) points.push(entity);
});
if (points.length === 0) {
log('No active spawn point: players start at the scene origin');
return;
}
let total = 0;
for (const point of points) total += point.getComponent(SpawnPointComponent).props.priority;
for (const point of points) {
const { priority, slots } = point.getComponent(SpawnPointComponent).props;
const chance = Math.round((priority / total) * 100);
log(`${point.name}: ${chance}% chance, ${slots} slot(s)`);
}
}

How it works:

  • scene.entities is a map of every entity in the scene; instanceof SpawnPointEntity keeps the spawn points, and isEnabled() keeps those that take part in the draw.
  • The draw is weighted by priority, so each point’s chance is its priority divided by the sum of all priorities.
  • props holds the current settings of the Spawn Point component, read with getComponent(SpawnPointComponent).

Put a fallen character back on its spawn point during play, without reloading the scene.

FallBack.jx
#pragma lifecycle(startup, update)
const KILL_HEIGHT = -20; // metres
const here = new THREE.Vector3();
const start = new THREE.Vector3();
let character;
let entrance;
function startup() {
// The player character has a Character Controller; 'Main Entrance' is a Spawn Point.
character = findEntity('Player')?.getComponent(CharacterControllerComponent);
entrance = findEntity('Main Entrance');
}
function update() {
if (!character || !entrance) return;
character.entity.getWorldPosition(here);
if (here.y > KILL_HEIGHT) return;
entrance.getWorldPosition(start);
character.teleport({ x: start.x, y: start.y, z: start.z });
emit('player/respawned');
}

How it works:

  • A spawn point does not move the player during play, so the script uses the Character Controller’s teleport, which places the capsule at once and cancels the fall.
  • getWorldPosition reads where the spawn point stands in the world, even when it sits inside a group.
  • emit('player/respawned') lets other scripts react, for example to reset a timer or show a message.
  • Keep the area around a spawn point flat and clear. Slots move players only across the ground, out to radius, so a slot inside a wall or on a step puts a player there.
  • A spawn point enabled during play only joins the draw for the next scene load. It moves no one by itself.
  • If players arrive facing the wrong way, rotate the spawn point entity itself: its forward (-Z) is the facing.

What a new Spawn Point is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Spawn Point comp-spawn-point Required One Marks where the player enters the scene. With several, one is picked by priority each time the player joins.

You can also add 1 optional components, such as Signal Emitter.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
priority 1 0.1 ≤ x ≤ 1
radius 0.6 0 ≤ x ≤ 100
slots 1 1 ≤ x ≤ 256

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • SpawnPoint::place

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Spawn Point.

SpawnPointEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Spawn Point');
if (!(entity instanceof SpawnPointEntity)) return;
// Its Spawn Point component holds the settings listed under Props.
const component = entity.getComponent(SpawnPointComponent);
log('priority is', component.props.priority);
component.setProps({ priority: 1 });
}