Templates
Templates are YAML files that tell the game how to build a station procedurally. Instead of placing every block by hand, you define small segments (ship designs with connection ports) and the rules for how they connect. The game then assembles a unique station by growing outward from a starting segment.
| Property | Value |
|---|---|
| Folder location | mods/{mod_name}/assets/templates |
| File format | .yml |
| Produces | A ship (voxel grid + equipment) |
| Referenced design path | Relative to assets/designs/, without the .zip extension |
How it works (in one paragraph)
The game places the anchor segment at the center, then repeatedly picks an unused connection port and attaches another segment to it, rotating the new segment as needed to line up the ports. While a goal (such as "3 docks" or "5000 m³ cargo") is unmet, growth is biased toward segments that provide the missing amount. It stops when every goal is met, a segment limit is reached, or no port can accept anything. The same template with the same seed always produces the same station.
A minimal template
Here is a trimmed-down station template:
yaml
label: "Station Civil 01"
inputs:
- key: "cargo_space"
label: "Cargo Space"
type: "Int"
defaultValue: 5000
unit: "m³"
- key: "docks"
label: "Docking Ports"
type: "Int"
defaultValue: 3
unit: "count"
anchor: "hub_6"
segments:
- id: "hub_6"
variants:
- design: "segments/stations/civil/connection_b"
rotation: "Yaw"
next:
- segment: "arm"
weight: 3
ports:
side_a: [ "side_a", "side_b" ]
side_b: [ "side_a", "side_b" ]
- id: "arm"
variants:
- design: "segments/stations/civil/connection_a"
rotation: "Yaw"
next: [ ]
- id: "cargo"
provides:
cargo_space: 1000
variants:
- design: "segments/stations/civil/cargo_a"
rotation: "Yaw"
next: [ ]Top-level fields
| Field | Type | Description |
|---|---|---|
label | string | Human-readable name of the template. |
anchor | string | id of the segment placed first, at the station center. |
inputs | list | The goals this station can be asked to satisfy. |
segments | list | The segment definitions. |
Inputs (goals)
inputs describe what a caller can ask the station to have. Each input is a goal the generator tries to reach by placing segments that provide it.
| Field | Type | Notes |
|---|---|---|
key | string | Unique identifier, referenced by a segment's provides. |
label | string | Human-readable name (shown in UI). |
type | string | Int, Float, Bool, or Enum. |
defaultValue | string | The fallback goal, used when the caller does not specify one. |
min / max | number | Optional allowed range (form/validation metadata only). |
options | list | Allowed values (for Enum). |
unit | string | Display unit, e.g. "m³". |
description | string | Longer description. |
Only Int inputs can be used as goals (that is, referenced by a segment's provides). If a segment
provides an input, that input must be Int and must have a defaultValue that is a non-negative integer.
Segments
A segment is a "role" in the station — for example a hub, an arm, a cargo hold, or a dock. Each segment has one or more variants (the ship designs it can be built from) and a list of next transitions describing what can attach to its ports.
| Field | Type | Notes |
|---|---|---|
id | string | Unique identifier, referenced by anchor and next. |
variants | list | The ship designs this segment can be. |
next | list | Transitions to other segments (what connects to which port). |
provides | map | Goal contributions, as key: amount. |
maxCount | int | Optional cap on how many times this segment can be placed (0 or omitted = unlimited). |
Variants
Each variant points at a ship design and says how that design may be rotated.
| Field | Type | Notes |
|---|---|---|
design | string | Path to a ship design (see below). |
rotation | string | Fixed, Yaw, Pitch, Roll, or Free. |
weight | int | Optional probability weight (default 1; 0 disables the variant). |
reserved | list | Optional clearance boxes (see Reserved space). |
docking | list | Optional ship-approach boxes (see Docking space). |
The design path is relative to assets/designs/, without the .zip extension. For example, segments/stations/civil/connection_a refers to assets/designs/segments/stations/civil/connection_a.zip.
Rotation
A variant's design is a voxel ship. When it is attached, it can be rotated to line up its ports. The rotation field limits which rotations are allowed:
| Value | Meaning |
|---|---|
Fixed | No rotation — the design is used exactly as saved. |
Yaw | Rotate around the vertical (Y) axis — 4 orientations. |
Pitch | Rotate around the X axis — 4 orientations. |
Roll | Rotate around the Z axis — 4 orientations. |
Free | Any of the 24 cube rotations. |
Use Yaw for "upright" segments (most connectors, cargo, docks) so they can face any horizontal direction but never flip upside down. Use Fixed for a segment that must keep its exact saved orientation.
Connecting segments
A segment attaches to another through connection ports. Ship designs can define named ports (for example side_a, top, small_b); a next transition maps the ports of this segment to the ports of the target segment.
yaml
next:
- segment: "arm"
weight: 3
ports:
side_a: [ "side_a", "side_b" ] # from "side_a", attach to the arm's "side_a" or "side_b"
side_b: [ "side_a", "side_b" ]segmentis the target segmentid.weightbiases how often this transition is picked (default1;0disables it).portsmaps a source port name to the list of acceptable target port names.
A port can only be used once — a segment cannot grow two children from the same port.
Providing goals
A segment can contribute toward an input goal by listing provides:
yaml
- id: "cargo"
provides:
cargo_space: 1000
# ...When this segment is placed, cargo_space increases by 1000. The generator keeps growing until every goal input's amount is reached, then stops.
If a template has no provides at all, it simply grows until the segment limit is reached, because there are no
goals to satisfy.
Reserved space
Sometimes a segment needs empty space around it — a margin so two pieces do not sit too close, or a corridor that must stay clear. Add reserved boxes to a variant:
yaml
variants:
- design: "segments/stations/civil/dock_a"
rotation: "Yaw"
reserved:
- min: [ -6, -2, -2 ]
max: [ 2, 2, 2 ]minandmaxare the opposite corners of an axis-aligned box, in the segment's local voxel space.- Reserved boxes may overlap other reserved boxes (two adjacent segments can share a margin).
Docking space
A dock segment needs a long, clear corridor in front of it so a ship can fly in and dock. Add docking boxes:
yaml
variants:
- design: "segments/stations/civil/dock_a"
rotation: "Yaw"
docking:
- min: [ -134, -10, -11 ]
max: [ -7, 13, 12 ]- Like
reserved,dockingis a localmin/maxbox. - Docking boxes may overlap
reservedboxes, but may not overlap solid geometry or other docking boxes (two ships approaching at the same time must not intersect).
INFO
reserved and docking boxes use min/max (rather than center + size) so you can place a corridor that is centered off-grid, for example an even-sized opening.
Symmetry
Stations can be generated with 180° rotational symmetry around one axis: a branch grown on one side is automatically mirrored to the other side.
This is a generation option (set by the code that generates the station, not written in the template YAML). The relevant point for a template author is the constraint it imposes:
A segment can only be mirrored around the axis it is allowed to rotate about. A Yaw segment mirrors only
around the Y axis, Pitch only around X, Roll only around Z, and Free around any axis. Fixed segments never mirror.
So a template built from Yaw segments is symmetric around the vertical (Y) axis — the natural look for a station that grows outward in the horizontal plane.
Generating a station from a mod
Templates are regular assets: look one up by name with Registry.findTemplate(name), then ask an entity to generate it. The entity needs a grid component first (and an equipment component if the template defines turrets), because the generator writes the voxels and turrets into them.
ts
import { Entity, Matrix4f, Registry, SymmetryAxis } from "@temporary-escape/mod-sdk";
export function onSpawn(entity: Entity): void {
entity.addTransform(Matrix4f.identity());
entity.addGrid();
entity.setGridScale(3); // the generator keeps the grid scale you set here
entity.addEquipment();
// Goal values for the template's `inputs`. Missing inputs use their `defaultValue`.
const inputs = new Map<string, u64>();
inputs.set("cargo_space", 20000);
inputs.set("docks", 4);
entity.generateTemplate(
Registry.findTemplate("station_civil_01"),
1234, // seed: same seed + options = same station
24, // maxSegments: hard cap; the anchor counts as one
SymmetryAxis.Y, // mirror around Y; `None` disables symmetry
inputs,
);
}generateTemplate takes the generation options as individual arguments:
| Argument | Description |
|---|---|
seed | Generation seed. |
maxSegments | Maximum number of placed segments (1–256). |
symmetryAxis | SymmetryAxis.X/Y/Z, or SymmetryAxis.None to disable symmetry. |
inputs | Optional Map<string, u64> of goal values for the template's inputs. |
WARNING
Call generateTemplate before addCollisionShape and addRigidBody. Static collision bodies must not be moved once they are in the physics world, so any custom placement has to happen while the entity still has no rigid body. The host rejects the call if the entity already has a rigid body. If a collision shape exists but no body, it is rebuilt from the generated grid.
Spawn arguments
An entity template or generator receives its spawn args as a flat map of string to scalar. In sector YAML they are written as nested maps under args; nested maps are flattened to dotted names before the WASM module sees them:
yaml
args:
template:
name: "station_civil_01"
inputs:
docks: 4
scale: 3The mod reads template.name, template.inputs.docks and scale. Use nesting to group related values. Dots are reserved for this flattening, so a literal template.name: key is rejected, and lists are not supported as spawn args. Numbers and booleans are inferred from unquoted scalars, so quote only values that must stay strings (for example symmetry: "y").
Choosing where a generated station spawns
A generated station can place itself at a random, collision-free position. This must happen inside the entity's onSpawn, after the grid is generated (so the station's real size is known) and before the static rigid body is added. The base mod's base:station entity does exactly this; the sector entry is the complete preset:
yaml
spawns:
- type: "base:station"
args:
template:
name: "station_civil_01"
maxSegments: 24
symmetry: "y"
inputs:
cargo_space: 20000
docks: 4
scale: 3
label: "Faction Academy"
spawn: "random"| Argument | Default | Description |
|---|---|---|
template.name | none | Procedural template asset name. Without it nothing is generated. |
template.maxSegments | 10 | Maximum number of placed segments (the anchor counts as one). |
template.symmetry | "none" | "x", "y", "z" or "none". Quote it: a plain y is a YAML boolean. |
template.inputs.<key> | template default | Goal values for the template's inputs. |
scale | 1 | Voxel grid scale; the generator preserves it. |
label | "" | Entity label shown in the UI. |
spawn | "fixed" | "random" picks a free position; anything else uses position. |
spawnDistance | 4000 | Maximum horizontal (XZ) distance from the sector origin. |
spawnHeight | 400 | Maximum vertical (Y) offset. |
spawnClearance | 100 | Extra padding added to the station's bounds radius when testing for collisions. |
position | (0, 0, 0) | Fixed position, used when spawn is not "random" or no free candidate is found. |
Only spawnDistance, spawnHeight and spawnClearance are configurable; the number of placement attempts is fixed in the SDK.
Vector args such as position and orientation cannot be written in sector YAML (spawn args are scalars); generators pass them through SpawnArgsBuilder instead.
Random placement is seeded from the sector spawn seed by the base mod, so the same sector seed always produces the same station position. Only entities that already have a collision body at generation time are avoided; later generators (such as asteroid fields) should avoid the station themselves.
TIP
Template inputs are passed as template.inputs.<key>, for example template.inputs.cargo_space: 20000. Inputs that are not passed fall back to the template's defaultValue, so a sector spawn entry can configure a generated template without changing the entity code.
Placing fields and formations
Multi-entity placement (container grids, ship formations) is a generator's job. Generators receive a seeded random number generator and can reuse the same placement helper:
ts
import {
engine,
findRandomFreePosition,
SpawnArgsBuilder,
Vector3f,
} from "@temporary-escape/mod-sdk";
const radius = 30; // the spawned entity's bounds radius (+ any padding)
const center = new Vector3f(0, 0, 0);
const position = findRandomFreePosition(engine.sector.scene, ctx.rng, radius, center, 2000, 400);
if (position !== null) {
ctx.spawn("base:asteroid", new SpawnArgsBuilder().setVector3f("position", position).build());
}findRandomFreePosition returns null when no free candidate was found, so the generator can decide whether to skip the entity or fall back to a known position.
The SDK has two placement helpers that share the same collision test; pick by intent:
| Helper | Search region | Use for |
|---|---|---|
findRandomFreePosition(scene, rng, radius, center, distance, height) | Bounded disc around center | Filling a known region during world generation. |
findRandomFreePositionOutward(scene, rng, radius, center, distance) | Expanding rings starting at distance from center | Spawning away from a point (a player, a command) where the nearby volume may be blocked. |
Both return null when no free position is found, and both are deterministic for a given RNG stream.
How generation works (optional)
You do not need to understand this part to author a template — it is a brief description of what the game does
with your rules.
- The anchor segment is placed at the center.
- The generator looks at every open port and every
nexttransition and builds a list of possible placements (each segment/design, rotation, and target port combination that fits without colliding). - It scores those placements and picks one at random, weighted by:
- the
weightvalues you wrote (transition weight × variant weight), - goal bias — segments that provide a still-unmet goal are strongly preferred,
- shape bias — growth that stays compact and spread out, rather than one long arm.
- the
- The chosen segment is rotated into place, merged into the station, and its own ports become new growth points. If symmetry is enabled, a mirrored twin is placed too.
- It repeats until every goal is met, the segment limit is reached, or no port can accept anything.
Generation is deterministic: the same template with the same seed and the same goal values always produces the same station.
Constraints and gotchas
- Every input
keymust be unique. - A
provideskey must reference anIntinput that has a non-negative integerdefaultValue. - At most 32 distinct goal inputs are allowed.
anchormust be an existing segmentid.- Every
next.segmentmust be an existing segmentid. - Every port name in a
next.portsmap must exist on the source design. - The target design must have a port compatible with each source port (matching size and orientation).
reservedanddockingboxes must haveminless than or equal tomax.- Every variant must reference a valid
design.
