Skip to content

Editor

Updated

MIRA runs a world in one of two modes. In the editor, the world is being authored: the simulation is frozen so you can place and tune things without them moving away. In play, the world runs: scripts, physics, interaction and networking all start. The two modes never mix, so a visitor’s player carries no editor code and pays no cost for it. This page explains what runs in each mode, how scripts behave in each, and how to give a script tools that help you author.

  • Basic principles introduces scenes, entities and Behavior scripts.
  • Lifecycle hooks explains startup and update, which run in play only.
  • Slots explains the editor fields a script declares; editor tools are built on them.
  • Editor. The scene stays exactly as authored. Nothing ticks: no script hooks, no physics steps, no animations playing on their own. The editor draws its own helpers instead, such as gizmos and icons, and has its own selection. When you leave a scene in the editor, your edits are kept with it.
  • Play. The scene runs from its saved state. Scripts start, physics steps, pointers and controllers interact with objects, and networked objects join their room. When a scene leaves play, it is freed, and it starts again as saved the next time it loads.
Feature Editor Play
Behavior scripts Only editor code: #editor_only scripts and #editor_begin regions Yes, through their hooks
Physics Not stepped Stepped
Selection, grabbing and handles in the scene No; the editor has its own selection Yes
Enable on Signal Ignored, so the saved state never changes Yes
Spawn points Do not place the view Place the player when a scene loads
Don’t Unload Nothing moves between scenes Marked entities move to the scene that stays
Networking Never connects Joins the room when a networked object appears
Scene switching from scripts (Scenes.load, Scenes.unload) Throws Yes
Notifications (NotificationService.show) Does nothing Shows them
Leaving a scene Edits are kept with the scene The scene is freed and starts as saved next time
Gizmos, icons and helpers Yes Never built

Some components behave differently by design. A Billboard turns only UI panel content in the editor, so the saved rotation never changes. A video never plays by itself while you author.

A Behavior’s hooks (startup, update, enable, disable, dispose) run in play only. In the editor no hook runs, so a spinner stands still and a script’s startup waits until you press Play.

A script can still carry editor code: functions that run when someone presses one of its buttons or changes one of its fields in the editor. Editor code lives between #editor_begin and #editor_end, or fills a whole script that starts with #editor_only. It is compiled separately and is absent from the player: a visitor never downloads, checks or runs it.

Play code Editor code
Runs Through the lifecycle hooks When a slot sends an event (a button pressed, a value changed), or needs validating
Every global Yes Yes
self, scene The running scene The scene being edited
slot(ref), a live handle to a slot No Yes
Editor: the selection and the viewport camera Throws Yes
Scenes.load, Scenes.unload Yes Throws
Scenes.list, Scenes.active, Scenes.find Yes Yes

Editor code is covered in full in Editor scripts, and #editor_begin with the other directives in Directives.

The Editor global gives editor code the selection and the viewport camera: see Editor scripts.

The script spins its parent in play. In the editor, a Reset rotation button puts the parent back straight.

SpinnerWithReset.jx
#pragma slot(ref=speed, type=Slider, min=0, max=10, default=2)
#pragma slot(ref=reset, type=Button, label="Reset rotation", on_event=onReset)
#pragma lifecycle(update)
function update(dt) {
self.parent.rotation.y += speed * dt;
}
#editor_begin
function onReset() {
self.parent.rotation.set(0, 0, 0);
log('Rotation reset on', self.parent.name);
}
#editor_end

How it works:

  • update is play code: it runs only after you press Play.
  • The reset slot is a Button in the editor. on_event=onReset names the editor function it calls.
  • onReset sits in an editor region, so it exists only in the editor and never ships to the player. In editor code, self is the Behavior entity in the scene being edited.

2. An editor tool that lines up the selection

Section titled “2. An editor tool that lines up the selection”

A whole #editor_only script is a tool: it never runs in play. This one lines the selected entities up along x.

RowTool.jx
#editor_only
#pragma slot(ref=spacing, type=Number, default=2, min=0.1, max=20)
#pragma slot(ref=align, type=Button, label="Line up selection", on_event=onAlign)
function onAlign() {
const selected = Editor.selection();
if (selected.length < 2) {
log('Select at least two entities.');
return;
}
selected.forEach((entity, i) => entity.position.set(i * spacing, entity.position.y, 0));
}

How it works:

  • #editor_only must be the first directive: it makes every line editor code, and play skips the script without an error.
  • Editor.selection() returns the selected entities in the order you selected them.
  • spacing holds the slot’s saved value when the button is pressed. Changing the field changes the gap the next time you line up.

Hooks run in play only. A script that animates something shows nothing in the editor until you press Play. To change the scene while authoring, use an editor button, as example 1 does.

Editor code sees only its own functions, the slot variables and the globals. A function declared in play code does not exist in the editor region.

Wrong
function straighten() {
self.parent.rotation.set(0, 0, 0);
}
#editor_begin
function onReset() {
straighten(); // not defined in editor code
}
#editor_end
Right
#editor_begin
function straighten() {
self.parent.rotation.set(0, 0, 0);
}
function onReset() {
straighten();
}
#editor_end

Scenes.load and Scenes.unload throw in editor code, because they would change the scene being edited. Open the other scene in the editor instead, or switch scenes from play code.

Every Editor member throws in play. Keep Editor calls inside #editor_begin regions or #editor_only scripts.

Wrong
#pragma lifecycle(startup)
function startup() {
log(Editor.selection().length); // throws in play
}
Right
#editor_only
#pragma slot(ref=count, type=Button, label="Count selection", on_event=onCount)
function onCount() {
log(Editor.selection().length, 'selected');
}

Expecting Enable on Signal to react while editing

Section titled “Expecting Enable on Signal to react while editing”

Signals are ignored by Enable on Signal in the editor, so the saved state of your scene never changes behind your back. Test signal wiring in play.