Skip to content

Headless mode and the command model

API → Editor

The editor from the C++ side: the process object (conjure/editor/editor_application.h, conjure/editor/editor_options.h), which projects it opens (conjure/editor/project_trust.h), the service table (conjure/editor/editor_context.h), the command model (conjure/editor/command_dispatcher.h, conjure/editor/command_registry.h, conjure/editor/editor_command.h, conjure/editor/builtin_commands.h, conjure/editor/schema_validator.h), the services commands drive (conjure/editor/undo_stack.h, conjure/editor/selection_set.h, conjure/editor/play_controller.h, conjure/editor/persist_list.h, conjure/editor/play_edit_log.h, conjure/editor/picker.h, conjure/editor/screenshot_service.h, conjure/editor/editor_camera.h, conjure/editor/console_buffer.h), addressing (conjure/editor/entity_ref.h, conjure/editor/reflection_path.h), events (conjure/editor/event_broadcaster.h), what a module adds (conjure/editor/command_desc.h, conjure/editor/panel_desc.h, conjure/editor/editor_module_consumer.h), the user's own settings (conjure/editor/user_settings.h) and the hook the windowed UI registers (conjure/editor/editor_ui_host.h).

Syntax

Usage and complete examples are described in the reference sections below.

At a glance

You want to... Use
Run the editor headless from a test or tool editor_options { headless = true, projectPath, aiPort = 0 }, editor_application::initialise(options, {}), pump_frame()
Open a project the editor did not create answer for it first: options.trustProject = true for this run, or application.trust().trust(root, remember, origin); see Project trust
Send a command from C++ context.dispatcher().dispatch(request) (a response, or nullopt for an asynchronous one that answers through a sink)
Register a command context.registry().add(command_descriptor); from a module, a command_desc extension record
Add a panel from a module a kit_panel_desc extension record that draws with the widget kit (the older panel_desc is deprecated); editor_module_consumer attaches it
Resolve "Board/Cell_3" or a guid to an entity entity_ref::resolve(json, scene), entity_ref::guid_of, entity_ref::path_of
Read or write one field of a component by path reflection_path::parse("transform.position.x"), read_at, write_at
Undo and redo programmatically context.undo(): pop_for_undo(), pop_for_redo(), begin_transaction, end_transaction
Switch play state context.play(): start(), stop(mode), pause(), resume(), step(n, reply)
Keep a value from play context.play().pin(persist_request), unpin(...), persisted(); stop(play_stop_mode::APPLY_PINS) writes it back; see Play-mode persist
Pick what is under a viewport point gather_pick_candidates(scene), pick(ray, candidates, context, mode)
Read or change the user's settings (theme, recent projects, UI scale, ligatures) context.user_settings(); update_user_settings(context.user_config_directory(), change) to keep a change; see User settings and the UI host
Reach the windowed UI from a command context.ui_host(), NOT_AVAILABLE when it is null (headless)
Save a screenshot as lossless JPEG XL instead of PNG view.screenshot with a .jxl path or "format": "jxl"; screenshot_request::format = screenshot_format::JPEG_XL from C++

Variables and Properties

Types, fields, and state are described in the reference sections below.

The process object

editor_options is the parsed command line (parse_editor_options(args)): projectPath, execFile, outputFile, exportDirectory, exportDistribution (--distribution <dir>, only with --export: the folder conjure_runtime, conjure_shared, shaders/ and THIRD_PARTY_NOTICES.txt are copied from, with nethost.dll and the Visual C++ runtime DLLs when it holds them; without it the export holds the pack and the project files only and its reply warns that the runtime was not copied; a folder without the notices, or on Windows without the runtime DLLs, exports with a warning, and debug runtime DLLs in it are left behind with a warning), aiToken and aiInspectToken (--ai-token <t>, --ai-inspect-token <t>; left empty, the server generates the tokens for its TCP port; an empty value on the command line is refused, and so is the same text for both; see Access tokens and the audit log), aiPort (0 disables the server), timeoutSeconds (a positive finite number; 0 is refused), headless, offscreen, keepGoing, aiStdio, noScripting, dotnetHost (--dotnet: a headless session keeps the real .NET script host), trustProject and trustStoreFile (--trust-project, which needs --project, and --trust-store <file>; see Project trust), userConfigDirectory (--user-config <dir>, read as UTF-8 whatever the code page: the folder of the user's own settings, themes and recent projects, for tests, agents and portable installs; see User settings and the UI host), showHelp and engineArguments (everything the editor did not recognise goes to the engine's parser; an option the engine does not know either fails with engine_error::BAD_ARGUMENTS, exit code 3, before the project is loaded). An empty value of --ai-token, --ai-inspect-token, --trust-store or --user-config is refused. --scripting is one of those engine flags: a headless session already runs scripting (null host, or .NET with --dotnet), so it only changes a windowed session of a project whose scripting.enabled is false; together with --no-scripting it is engine_error::BAD_ARGUMENTS, exit code 3.

Two members have no flag; an embedder or a test sets them, and each replaces a rule when set. recordRecentProjects decides whether the session records the projects it opens in the user's recent list (the rule: records_recent_projects(options)). fallBackToStartScreen decides whether a --project that cannot be opened leaves the session on the start screen instead of failing (the rule: falls_back_to_start_screen(options)). Both rules hold for a windowed editor run by a person: not --headless, --exec or --export.

editor_options_help() is the usage text --help prints: the editor's options followed by the engine's (engine::command_line_help(), without the --project, --headless, --no-scripting and --help lines the editor describes itself, and without the engine's note that unknown options are passed on). stdout_carries_protocol() is true for --ai-stdio, --exec without --out and --export; conjure_editor then sends every log line to standard error.

editor_application::initialise(options, uiFactory) builds the engine (headless: null platform, rhi and audio, the script runtime on the null host so script.* works without .NET), adds bindings::scripting_bindings_subsystem before initialise() so every native API slot the C# facades call is filled (📘 The native table), creates the context, pushes the frame layer and, with a factory, the UI layer, and starts the protocol server. startup_scene_warning() is the {code: "STARTUP_SCENE_FAILED", message} of a startup scene the engine could not load (engine::application::startup_scene_failure()), which an --exec output opens with (📘 The AI control protocol). run() exports (--export), executes (--exec) or loops frames; pump_frame() runs one engine frame and applies a pending project.open; request_open_project(dir) restarts the engine on another project at the next frame boundary (the AI port file moves with it; PROJECT_NOT_TRUSTED, and no restart, for a project nobody answered for), stopping a play session first, and play.start answers BUSY while such a restart is pending; make_engine_desc(options, projectPath) shows the merged engine configuration. A headless --ai-stdio session without a TCP server ends run() with 0 once standard input ends.

editor::editor_options options = {};
options.headless = true;
options.aiPort = u16{0};
options.projectPath = scratch.path();
options.trustProject = true;        // your own project: answered for this run, remembered nowhere
options.engineArguments = {"--log-level", "warn"};
editor::editor_application app = {};
CONJURE_TRY(app.initialise(options, {}));

editor::protocol_request request = {};
request.id = editor::make_id(i64{1});
request.command = "entity.create";
request.args = core::json::object({{"name", "Player"}});
const std::optional<editor::protocol_response> response = app.context().dispatcher().dispatch(request);
// a synchronous command answers at once; an asynchronous one answers through the client's response sink

Important

--offscreen asks for a real device without a window so view.screenshot has pixels. The engine configuration refuses that today (headless rendering means the null device), the editor logs a warning and falls back to the null device, and view.screenshot answers NOT_AVAILABLE.

The startup order

initialise checks everything that needs no engine before it starts one, so a mistake costs no window, device or asset scan. In order:

  1. The arguments, project.json and the merged configuration (make_engine_desc). A bad or unknown flag fails with engine_error::BAD_ARGUMENTS (exit code 3). A --project that cannot be opened (project.json missing or invalid, or settings that do not validate even without an engine flag) fails the start (exit code 2), unless falls_back_to_start_screen(options) holds: then the engine starts without a project, options().projectPath is empty, and startup_problem() holds the sentence the start screen shows, "The project '' could not be opened: ".
  2. The log file. The file the engine flag --log-file names is held from here on, so everything that follows reaches it. The fall-back's one ERROR is logged now, after the file is held, so the log of a windowed run without a project says why; a refusal at any later step is logged before initialise returns it.
  3. The --exec file, read and parsed (headless_runner::load_command_file), unless --export is given as well (an export wins). A missing or malformed file fails with engine_error::BAD_ARGUMENTS (exit code 3).
  4. Project trust, over the project that is left (plan_startup). A project that fell back to the start screen is never asked about. A project nobody answered for fails the start with PROJECT_NOT_TRUSTED (exit code 2) where nobody can be asked (--headless, --exec, --export); a windowed session starts without it, and the window asks (Project trust).
  5. The engine. It starts over the project the trust check let through, and no other. The context is created (its user configuration folder resolved and its editor_settings.json loaded), the trust question is raised, the protocol server starts (headless, a busy explicit --ai-port fails with IO_ERROR; a windowed editor logs it and runs without the server), and a windowed session records its project as the most recent one.

A windowed session whose --project was not opened shows the start screen, and one of two states says why:

State When What the window shows
editor_application::startup_problem() (not empty) the project could not be opened at all (step 1) the start screen, with the reason as its Open problem until the next Open; startup_problem() itself is emptied by a project.open restart
editor_context::trust_prompt() (names the folder) the project could be opened, but nobody answered for it (step 4) the start screen, with the question "Trust this project?" over it

A --headless, --exec or --export run has neither: it exits with 2.

Project trust

Opening a project runs code from its folder with your rights: the engine loads the project's native modules and its game assembly while it starts, and script.compile, module.build and play.start run more of it. The editor therefore opens a project only after somebody answered for it. There is one gate, at the opening, and an untrusted project is not opened at all; there is no mode that opens it without its code.

Where A project nobody answered for The explicit answer
The editor window the editor starts without it, on the start screen, and asks "Trust this project?" in a dialog over it Trust and open, or Don't open (also Escape; nothing is recorded). Enter does not trust: only a press of Trust and open does
--headless, --exec, --export initialise fails with PROJECT_NOT_TRUSTED before the engine starts (exit code 2) --trust-project for this run, or an earlier project.trust
project.open PROJECT_NOT_TRUSTED with details {path, state, prompt}; nothing is scheduled, and a window asks the person at it project.trust {path} first
request_open_project(dir) PROJECT_NOT_TRUSTED application.trust().trust(dir, remember, origin)

project_trust keeps the answers; editor_application::trust() is the one the application asks, and editor_context::trust() points at it. trust(root, remember, origin) records an answer and returns the trust_state the project now has: REMEMBERED when the trust store took it, SESSION when it holds until the editor exits (not asked to remember, no store, or a store that could not be written or did not show the answer right after it was written, which is a WARN and not an error). state_of(root) and is_trusted(root) ask, revoke(root) takes an answer back, remembered() lists the store. A project is project_key(root): the resolved absolute path of its root folder.

The trust store is one JSON file per user of the machine, outside every project, so that a project cannot bring its own answer. default_trust_store_file() names it: trusted_projects.json under %LOCALAPPDATA%/Conjure, under $XDG_STATE_HOME/conjure or ~/.local/state/conjure, or under ~/Library/Application Support/Conjure. --trust-store <file> (editor_options::trustStoreFile) names another file. Only conjure_editor fills in the default: an editor_application you start with an empty trustStoreFile remembers nothing, so a test or a tool never writes to the user's folder. The file is written for its owner alone and is ignored, with a WARN, when another account could have written it, when it does not parse or when it is larger than 4 MiB; it keeps the newest 1024 answers. That check and the read are two steps on the path, so a file swapped in between them is believed: keep the store in a folder other accounts cannot write to (the default folder is one).

The commands are project.trust {path, remember?}, project.revoke_trust {path} and project.trust_state {path?} (the last one is read_only; the first two cannot run in a batch). project.create trusts the project it writes into a folder that did not exist (result.trust); a project created in an existing folder, even an empty one, is asked about like any other. The window's question is editor_context::trust_prompt(), which editor.state reports as trustPrompt; raise_trust_prompt, dismiss_trust_prompt and close_trust_prompt_for move it, and editor_application::can_ask_about_trust(options) says whether a session has a window to ask in. The question in the window, and what it does to the open flows of the start screen and the File menu, is on The workspace UI.

Important

A script that runs conjure_editor --headless --project <dir> ... must pass --trust-project, or trust the project once with project.trust. Without an answer the run exits with 2 and says so on standard error.

Warning

Trust belongs to the folder's path, not to its files. What is later put into a trusted folder runs without a question, a project that is moved or copied is asked about again, and revoking does not close the project that is open. A command file is commands: one that came with a project can answer for it, so read it before you pass it to --exec or editor.exec_file.

The service table

editor_context holds references into the running engine (engine(), engine_context(), scene(), scene_manager(), world(), components(), filesystem(), assets(), asset_database(), input(), renderer(), physics(), scripting(), modules(), frame_index(); the pointers are null for a disabled module) and owns the editor's own services: registry(), dispatcher(), undo(), events(), console(), selection(), camera(), play(), screenshots(), module_consumer(); trust() is the application's project_trust (null for a context built over a bare engine). has_project(), has_scene(), scene_path(), scene_dirty(), is_headless(), offscreen() describe the state; rebind(application) follows a project restart. user_config_directory(), user_settings(), themes() and ui_host() are the user's side (User settings and the UI host). normalise_scene_path(text) turns a scene argument into the canonical asset path the database registers (forward slashes, no . or .. segments, .scene.json matched without case) and answers "" for a path that leaves its mount, which scene.new, scene.open and scene.save_as refuse with INVALID_ARGS. is_open_scene(id) says whether an asset is the file behind the open scene and names_asset(path, id) whether an asset path names an asset's source file; both compare files, not spellings, so a scene opened as Scenes/Main on a volume that ignores case is the asset registered as scenes/main. viewport_aspect() is the width / height the viewport panel last reported (16:9 until then, and headless): view.pick builds its ray with it when the request names no aspect. script_compile_pending() is true while a script.compile runs (a second one answers BUSY), and last_script_configuration() names the configuration of the last successful compile, whose scripts/bin/<configuration>/Game.dll script.reload loads by default. Main thread only.

The command model

A command_descriptor is name, summary, argsSchema and resultSchema (a hand-validated JSON Schema subset: type, properties, required, additionalProperties, enum, items, minimum, maximum), flags (MUTATES, REQUIRES_PROJECT, REQUIRES_SCENE, EDITING_ONLY, PLAYING_ONLY, ASYNC, UI_ONLY, NOT_IN_BATCH, NO_UNDO, ON_DISK, READ_ONLY, SYNC_IN_BATCH), owner and the command_handler. The handler receives a command_invocation (context, args, clientId, an async_reply for ASYNC commands) and returns a command_outcome: result, the inverse (mandatory for MUTATES without NO_UNDO; skipRecording when nothing undoable happened), an optional normalised replay and an undo label. builtin_command_count() says how many the editor registers (120); command_registry adds, finds, lists (names(), closest_names(name, count) for didYouMean, empty for a name over 128 bytes) and describes commands (describe_all is editor.schema; schema_hash() the schemaHash, recomputed on first use after a change).

command_dispatcher::dispatch(request) runs the pipeline: unknown name, the scope of the client's token (UNAUTHORISED when required_access(flags) is above what the client was granted), schema validation, preconditions, handler, undo recording, revision, events, and the audit record of a transport client's request. execute(command_request) is the in-process form that returns the result document; run_batch runs children atomically (the rollback works while playing and when the batch is itself an undo or redo step, too); resolve_completed delivers finished asynchronous replies once per frame; cancel_client / cancel_all answer pending requests with CANCELLED; set_async_timeout_seconds, set_max_pending_per_client and set_clock tune the queue. dispatch_inverses / dispatch_replays apply an undo or redo step without recording, bumping the revision or emitting scene.changed: history.undo / redo do that once per step. replaying() is true meanwhile (and during a batch rollback), so a handler can accept a value an earlier state held that a client may not send, such as a legacy entity name. run_step(request, entry) runs one request like a batch child and appends its undo pair to an undo_entry the caller assembles, leaving the stack and any open transaction alone; rollback_steps(entry, first) takes the steps from first on back, newest first. Play-mode persist builds its Persist from play (N) entry that way.

An ASYNC command parks its request and answers through its async_reply, frames later; an asynchronous command that changes the scene is recorded, bumps the revision and emits scene.changed when it completes, not when it is dispatched. The registry adds NOT_IN_BATCH to an ASYNC command unless it carries SYNC_IN_BATCH: the promise that its handler answers before it returns whenever requires_synchronous_completion() is true (a batch child, an undo or redo step, a batch rollback). The prefab commands that load their asset are such commands. SYNC_IN_BATCH needs ASYNC and excludes NOT_IN_BATCH (command_registry::add answers INVALID_ARGS otherwise), and a module command loses it.

Entity names must be addressable by a hierarchy path: entity.create (args.name), entity.create_many (args.nameFormat), entity.rename, prefab.instantiate (args.name) and a write of the name component (component.set, component.set_many, entity.create's components.name) refuse the empty name and one holding / with INVALID_ARGS. Undo still restores such a name when a scene file or an import gave it. Identical names are allowed; an ambiguous path answers with details.candidates.

A write of the layer component (component.set, component.add's value, entity.create's components.layer) goes through scene::set_layer and refuses an index of 32 or more with INVALID_ARGS, leaving the component as it was: every capture (play.start's snapshot, scene.save, entity.duplicate, a prefab) refuses such an index. The 0..31 range reflection.components reports for the field is otherwise only an inspector hint; the write path does not enforce reflected ranges.

A component path whose leading segments spell a full registered name (transform.rig.weight with a registered transform.rig) addresses that type, even when its first segment is an alias or another type's short name; the inspector always sends the registered name.

Warning

A MUTATES handler that returns neither an inverse nor skipRecording is an INTERNAL error in the log: the command ran, but it cannot be undone. Module commands cannot return inverses, so their MUTATES is registered as MUTATES | NO_UNDO.

Flag a command ON_DISK when it is undoable and its effect lives in the project's files, not in the scene. play.stop restores the scene and nothing on disk, so while playing the dispatcher hands the inverse and replay of such a command to the play controller instead of dropping them, and play.stop makes one undo entry of them. The flag is a promise about both requests: neither the inverse nor the replay may refer to scene state, because they run after the restore. command_registry::add answers INVALID_ARGS for ON_DISK without MUTATES or together with NO_UNDO, and a module command loses the flag (it has no inverse to keep). A command that writes a file and changes the scene so that its inverse touches both is EDITING_ONLY instead, as prefab.create is.

Flag a command READ_ONLY when a client that holds only the inspect token may run it (Two tokens). The flag is a promise: the handler changes nothing clients share (the scene, a file, the selection, the camera, the play state, the console, the history), starts no program and loads no code; what belongs to the calling client alone, such as its event subscriptions, is its own. required_access(flags) is the whole rule (INSPECT with the flag, FULL_CONTROL without), so a command without the flag is closed to inspect-only clients by default. command_registry::add answers INVALID_ARGS for READ_ONLY together with MUTATES, and a module command that says both keeps MUTATES and loses READ_ONLY. The editor's own callers (the UI, --exec, editor.exec_file) always have full control.

User settings and the UI host

The person's own preferences live outside every project, in <user config>/editor_settings.json (conjure/editor/user_settings.h): editor_user_settings { activeTheme = "Midnight", recentProjects, uiScale = 100, codeLigatures = true }.

  • recentProjects is most recent first, at most MAX_RECENT_PROJECTS (10), each a recent_project { root, name } with an absolute, lexically normal root.
  • uiScale is a percentage from MIN_UI_SCALE (50) to MAX_UI_SCALE (300) that scales the editor's text and sizes.
  • codeLigatures switches the code font's ligatures (Fonts and code ligatures).
  • activeTheme is the theme the user chose (Themes).

The user configuration folder is --user-config when it is given, made absolute and lexically normal, otherwise the platform's (%APPDATA%/Conjure on Windows, $XDG_CONFIG_HOME/conjure or ~/.config/conjure on Linux, ~/Library/Application Support/Conjure on macOS); editor_application::user_config_directory_for(options) resolves it. When none can be resolved it is empty, after one WARN, and the settings live in memory only. editor_context::user_config_directory() and user_settings() hold them; both survive the rebind() of a project restart. A session for which records_recent_projects(options) holds records the project it starts on, and every project a successful project.open restart switches to, as the most recent one; a project.open that falls back to the previous project records nothing.

load_user_settings(folder) never fails. No file gives the defaults (user_settings_state::MISSING); a file that is not JSON, has a member of the wrong type or value (a uiScale outside its range among them) or cannot be read gives the defaults and one WARN (INVALID, UNREADABLE). Reading a file compares the recent roots by spelling only and never touches the disk, so a root on a drive or share that is offline costs nothing. add_recent_project(settings, root, name) moves a project to the front, dropping another entry for the same project (same_recent_root: the same spelling once normalised, or a spelling that differs in letter case alone for one folder on disk) and the oldest entry past ten; a link to a project folder is a second entry.

Several editors may run at once and share the file, so a change that must last goes through update_user_settings(folder, change): it re-reads the file, applies change and writes it atomically, creating the folder. record_recent_project(folder, root, name) is that with add_recent_project. Members this version does not know are kept.

Caution

A settings file the editor could not use is never written over silently: the next save first copies the bytes it read to editor_settings.json.bak, replacing an older backup. A file that could not be read at all is not saved over; the save fails instead. Two editors that save in the same instant can still lose one change: the last writer wins.

The windowed UI registers an editor_ui_host (conjure/editor/editor_ui_host.h) on the context with set_ui_host(host) while its layer is attached, and rebind() forgets it. Its calls only record a request, which the UI carries out at its next safe point: request_layout_reset() rebuilds the default layout before the next dockspace is drawn, and request_theme_refresh() applies the active theme again. A command that needs the UI asks ui_host() and answers NOT_AVAILABLE without one: editor.layout.reset and editor.theme.set do. A headless editor has no UI host, and tests register a fake one.

Undo, selection, play

undo_stack keeps undo_entry { label, undo[], redo[], coalesceKey, clientId, byteSize, source } (source, who made the entry, is set by the stack as the entry is pushed) up to 1024 entries and 256 MiB of serialised arguments: record(...) and push(entry), begin_transaction(label, clientId) / end_transaction group a client's commands, has_transaction(clientId) / has_open_transaction() (any client) report them, pop_for_undo() / pop_for_redo() hand the inverses and replays to the dispatcher, set_frozen(true) while playing, can_undo(), can_redo(), cursor(), size(), clear(). Consecutive single-command entries with the same coalesce key and client merge (the inspector's drags). history.undo, history.redo and history.clear answer INVALID_REQUEST while any transaction is open: ending it would push its entry at the cursor and drop the redo tail.

selection_set holds guids (set, add, remove, clear, contains, primary()) and a dense entity bitmap rebuilt from the scene (rebuild(scene)) for O(1) contains(entity) while drawing. guids() is sorted; primary() (the inspector's entity, selection.get's primary) is the guid named last in the set or add call that last changed it, so selection.set {"entities":[a, b]} makes b primary; when the primary leaves (remove, rebuild) the lowest remaining guid takes over, and play.stop restores it with the selection. editor_context::selection_payload() builds {guids, primary} with primary null when nothing is selected. Every selection.changed event carries exactly that (editor_context::emit_selection_changed() sends it, for the selection's on_changed and for play.stop), and selection.get / set / clear answer it plus entities and count.

play_controller maps the three editor states onto the engine: EDITING keeps the engine PAUSED and the script runtime in EDIT mode; start() snapshots the scene, freezes undo and runs; pause() / resume(); step(fixedSteps, reply) runs exactly n fixed steps and answers when they ran; stop(mode) restores the snapshot (guids preserved), remaps the selection and thaws undo, and with play_stop_mode::APPLY_PINS keeps the pinned values (Play-mode persist). state(), describe(), to_string(play_state). While the stack is frozen the dispatcher reports each recorded edit to the controller: note_unrecorded_edit(touched) for a scene edit (not recorded, discarded by the restore, warning UNRECORDED_PLAY_EDIT once per session; touched_in_play(guid) and touched_entities() answer the guids it named until the session ends, for the hierarchy's marker) and keep_file_edit(command, replay, inverse) for an ON_DISK command (warning PLAY_FILE_EDIT once per session). kept_file_edits() counts what the session holds, and stop() pushes it as one undo entry labelled play_controller::FILE_EDITS_LABEL ("File changes during play"), whichever way the session ends. The clocks of the play session are simulation_frame(), simulation_time() and simulation_fixed_steps(): start() sets them to 0 by recording the engine's fixedTime and fixedStepIndex, the time and the fixed steps advance with fixed steps only (so they stand still while paused), and after stop() they keep the ended session's values until the next start(). describe() reports them as simulationFrame, simulationTime and fixedStepIndex beside state and the engine frame.

Play-mode persist

Play-mode persist keeps chosen values when play stops, instead of discarding them with the snapshot restore. The protocol side (play.persist, play.unpersist, play.persisted and the two events) is on 📘 The AI control protocol; this section is the C++ side.

The play controller owns a persist_list (conjure/editor/persist_list.h), the pins of the play session. Each is a persist_entry { entity, scope, component, path, pointer, children, clientId, pinnedAtFrame } whose persist_scope is FIELD, COMPONENT or ENTITY.

  • play().pin(persist_request { entity, component, path, children, clientId }) validates the request (the error codes of component.set), promotes a pin on an entity created during play to ENTITY and one inside a component added during play to COMPONENT, and deduplicates: a pin that a wider one covers changes nothing, and a wider pin replaces the narrower ones. It answers persist_pin_result { entry, added, promoted, subsumed }.
  • unpin(persist_unpin_request { entity, component, path, all }) removes pins and answers how many went. Both emit persist.changed when the list changed, and both answer WRONG_PLAY_STATE while editing.
  • persisted() is the list: entries(), size(), is_pinned(guid) and version(), which moves on every change. marker_version() moves with it and with the entities touched in play, so a UI cache compares one number.

stop(play_stop_mode::APPLY_PINS) reads the pinned values with persist_list::capture(context, snapshot) before the script runtime leaves play mode (its OnDestroy calls may change the scene), restores the snapshot and applies them with persist_list::apply(context, captured) as one undo entry, labelled with persist_list::UNDO_LABEL_FORMAT ("Persist from play ({})"). Each pin is all or nothing. last_persist_report() is the persist_report { applied, skipped, undoLabel }; its to_json() is the persist.applied event and the matching members of the play.stop answer. stop() alone means DISCARD_PINS, for a scene that is thrown away next (the shutdown, the restart of project.open); play.stop, editor.quit {saveChanges} and a module detach apply them. The entry is built with the dispatcher's run_step and rollback_steps, through the ordinary commands, so a redo replays it.

snapshot() is the session's scene::scene_snapshot, and snapshot_component_json(guid, type) reads a component as play found it, in component.get's form, cached for the session. An unchanged component compares equal, with two exceptions: a running script's JSON carries its runtime state and every field of its class, where the snapshot's holds only the fields set before play; and a reflected reference to an entity destroyed during play reads as that entity's guid in the snapshot and as null live.

A running script's started and created flags are runtime state, not values. play.persisted strips both from its current and before, the values a pin keeps are stripped of both before they are written back (written back, the next play session would skip the script's OnStart and run OnReload in place of OnCreate), and same_as_edited(context, component, live, before) skips both when it compares a running script with its edited form.

Who changed what during play

conjure/editor/play_edit_log.h tells the Persist panel's "Changed by" column and play.persisted's changedBy who last changed what a pin keeps. While the scene plays, the dispatcher hands the controller every scene edit a command makes (note_play_edit(inverse, result, clientId)), and its play_edit_log keeps, for each place an edit reached (a value in a component, a whole component, or the entity as a whole), the latest edit's edit_origin and what that edit left. changed_by(entry) answers:

edit_origin Wire name When
NONE none nothing changed it this session (and always while editing)
EDITOR editor a command of the editor's own UI other than the two below: a menu, the Hierarchy
INSPECTOR inspector a command of the Inspector
GIZMO gizmo a command of a gizmo drag in the Scene panel
CLIENT client a command of a protocol client: an agent, a command file, the AI session panel
GAME game no command: the place no longer holds what the last command left (or, with no command, differs from the snapshot), so the running game changed it

The UI says which of its origins it is with an edit_origin_scope(play, origin) around the commands it sends; a protocol client's commands are always CLIENT. The log keeps at most play_edit_log::MAX_PLACES (4096) places and forgets the oldest past that; start and stop clear it. same_json_value(left, right) compares numbers by value and objects regardless of member order, and changed_from_edited(context, component, live, before, pointer) says whether play changed the value at one pointer.

Picking, screenshots, camera, console

pick(ray, candidates, context, mode) is CPU picking over pick_candidate { guid, worldBounds, entity } from gather_pick_candidates(scene) (active entities only: a disabled entity, or one under a disabled ancestor, is not pickable): a slab test over world bounds sorted by entry distance, then (pick_mode::MESH) the triangles of the mesh asset's CPU geometry, BOUNDS for bounds only, PHYSICS through Jolt; pick_context::maxDistance bounds both the bounds entry and the triangle hit. The result is pick_result { guid, point, normal, distance, hit } with to_json(). editor_camera is the viewport camera: set_look_at, focus(aabb), orbit, pan, zoom, perspective or orthographic, screen_ray(uv, aspect), world_units_per_pixel(viewportHeight) (the visible height at the target over the viewport's pixels, so a pan follows the cursor at any zoom), to_json() / apply_json() (what view.get_camera / view.set_camera exchange, fov in degrees). The viewport keeps orbiting or panning while a drag that started on it continues outside the panel. screenshot_service parks a screenshot_request { path, camera, format, width, height, waitFrames }, captures through a screenshot_backend on the main thread after the wait and encodes the file on a job. The renderer backend draws the scene through the requested camera into a render target of the requested size and reads it back; a frame counts as waited only once the engine has rendered one for the request (screenshot_backend::frame_rendered), so the capture is never an empty target. Pictures are taken one at a time, in request order: a request made while another waits is begun when its turn comes. Tests install memory_screenshot_backend, and headless there is no backend (available() false, NOT_AVAILABLE). view.screenshot's camera is "editor", "game" or an entity by guid, path or name that must carry a camera component (COMPONENT_NOT_FOUND otherwise); the service receives its guid. "game" is the scene camera the engine shows first (the main camera of the highest priority, any enabled camera when none is main), the one the Game panel shows. A scene camera is drawn as the runtime presents it, with its own settings and the debug lines the game draws. Where the scene draws nothing and has no sky, an "editor" screenshot shows an opaque grey and a scene camera's shows black; the Scene panel's own picture shows the theme's backdrop and the Grid there instead (The workspace UI).

A screenshot is a PNG unless it asks for JPEG XL (screenshot_format, wire names "png" and "jxl"):

view.screenshot arguments File written
path ends in .jxl (any case), no format lossless JPEG XL
any other path (.png, another extension, none), no format PNG, the default: golden images and review tools read it
"format": "jxl" or "png" with a path whose extension names no format (shot.bin) that format
format contradicting a .png / .jxl extension, or any other format INVALID_ARGS naming args.format

screenshot_format_of(path) is the extension rule and screenshot_service::parse_request applies the table; the answer carries format, so a client knows what it got. A JPEG XL screenshot holds exactly the pixels of the PNG one (sRGB, alpha kept) and is encoded at effort 2 by the renderer's encode_jpeg_xl (📘 API: JPEG XL images): faster than the PNG encode and usually a third to a half of its size. A build without the renderer module cannot write it: screenshot_service::supports(format) is false and the request answers NOT_AVAILABLE. console_buffer is the log ring the console.read command and the console panel read (install_sink(), read(console_query), clear()): read returns the oldest matches up to limit, or with console_query::newest the newest ones (still oldest first), which is what the panel draws so new lines keep appearing past its limit.

Addressing and events

entity_ref::resolve(json, scene) accepts a guid string, a hierarchy path or a unique name; resolve_many an array; guid_of(scene, entity) generates and indexes a guid where missing; path_of and to_json go the other way. reflection_path::parse("transform.position.x") splits a component (an alias, a unique registered-name suffix or the full name) from field segments and array indices; resolve(typeInfo) yields a field_ref (offset, field, is_whole_component()), read_at / write_at move JSON in and out of a component through the reflection description. event_broadcaster fans protocol_events out to clients (register_client, set_subscriptions, set_min_log_level, emit, make_event); the editor_event enumeration names the eighteen events.

What a module adds

A plugin registers command_desc { name, summary, argsSchema, resultSchema, flags, handler, userData } and panel_desc { title, draw, userData, openByDefault } records through its module_registrar; editor_module_consumer validates them (unique names, a parseable schema), attaches commands into the registry with owner = <module> and panels into the workspace, vetoes module.unload while playing, and strips both on detach. The module name editor is reserved (the owner of the built-in commands and panels): such a module fails validation with REGISTRATION_CONFLICT, and module.list counts commands only for a loaded module. module.* commands only enqueue requests; the module manager applies them between frames. A panel that draws with the widget kit registers a kit_panel_desc record instead (conjure/editor/kit_panel_desc.h); panel_desc, whose callback receives the raw ImGui context, still loads but is deprecated (📘 The widget kit).

Note

The editor loads its static modules before the consumer exists, so editor_context::install_module_consumer() unloads, adds the consumer and loads again at start-up; a pre-load hook on the modules subsystem is a recorded engine request.

Functions

Signature (short) Purpose
result<editor_options> parse_editor_options(span<const string_view>) / std::string editor_options_help() / bool editor_options::stdout_carries_protocol() the editor command line
result<void> editor_application::initialise(const editor_options &, layer_factory) / int run() / result<void> pump_frame() / void shutdown() the process object
editor_context &editor_application::context() / engine::application &engine() / protocol_server &server() its parts
project_trust &editor_application::trust() / static bool can_ask_about_trust(const editor_options &) the answers the application opens projects by, and whether a session has a window to ask in
static result<startup_project> resolve_startup_project(const editor_options &, project_trust &) / static result<startup_plan> plan_startup(...) what initialise does about --project: open it, leave it out for the window to ask about (unanswered), or PROJECT_NOT_TRUSTED; the plan adds the engine description, which holds no project that was left out
result<trust_state> project_trust::trust(const path &, bool remember, string_view origin) / result<bool> revoke(const path &) / trust_state state_of(const path &) / bool is_trusted(const path &) / vector<trusted_project> remembered() answering, taking back and asking
static result<string> project_trust::project_key(const path &) / void set_store_file(path) / result<path> default_trust_store_file() what a project is remembered under, and where
bool editor_context::raise_trust_prompt(const path &) / const optional<path> &trust_prompt() / void dismiss_trust_prompt() / void close_trust_prompt_for(const path &) the window's question
optional<json::document> editor_application::startup_scene_warning() {code: "STARTUP_SCENE_FAILED", message} when the engine started without the startup scene
const std::string &editor_application::startup_problem() / static bool falls_back_to_start_screen(const editor_options &) why --project could not be opened when the editor started on the start screen instead, and whether a session falls back so
static path editor_application::user_config_directory_for(const editor_options &) / static bool records_recent_projects(const editor_options &) the user configuration folder a session uses, and whether it keeps the recent projects
user_settings_load load_user_settings(const path &) / result<void> save_user_settings(const path &, const editor_user_settings &) / result<editor_user_settings> update_user_settings(const path &, const user_settings_change &) / record_recent_project(const path &, const path &, string_view) the per-user settings file
result<void> add_recent_project(editor_user_settings &, const path &, string_view) / bool same_recent_root(const path &, const path &) / path normalise_recent_root(const path &) the recent projects list
result<editor_user_settings> parse_user_settings(string_view) / std::string serialise_user_settings(const editor_user_settings &) the settings file's text
const path &editor_context::user_config_directory() / editor_user_settings &user_settings() / void set_user_settings(editor_user_settings) the user's settings on the context
editor_ui_host *editor_context::ui_host() / void set_ui_host(editor_ui_host *) / virtual void editor_ui_host::request_layout_reset() / virtual void request_theme_refresh() the UI hook
optional<protocol_response> command_dispatcher::dispatch(const protocol_request &) / result<json::document> execute(const command_request &) running a command
result<json::document> command_dispatcher::run_step(const command_request &, undo_entry &) / void rollback_steps(undo_entry &, usize) / bool requires_synchronous_completion() one undo entry built from several commands; whether a request must answer before its handler returns
constexpr access_level required_access(command_flags) what a client must have been granted to run a command: INSPECT for READ_ONLY, FULL_CONTROL otherwise
result<void> command_registry::add(command_descriptor) / json::document describe_all(bool) / vector<string> closest_names(string_view, usize) the catalogue
result<compiled_schema> compile_schema(string_view) / result<void> validate_args(const compiled_schema &, const json::value &) argument validation
optional<undo_entry> undo_stack::pop_for_undo() / pop_for_redo() / result<void> begin_transaction(string_view, u32) / end_transaction(u32) / bool has_open_transaction() undo
bool command_dispatcher::replaying() an undo or redo step (or a batch rollback) is being applied
f32 editor_camera::world_units_per_pixel(f32) / f32 editor_context::viewport_aspect() viewport scale and shape
bool editor_context::is_open_scene(const assets::asset_id &) / names_asset(string_view, const assets::asset_id &) whether an asset is the open scene's file, or the file an asset path names
result<void> play_controller::start() / stop(play_stop_mode = play_stop_mode::DISCARD_PINS) / pause() / resume() / step(u32, async_reply) play mode
u64 play_controller::simulation_frame() / f64 simulation_time() / u64 simulation_fixed_steps() the play session's clocks
void play_controller::keep_file_edit(string_view, command_request, command_inverse) / usize kept_file_edits() / void note_unrecorded_edit(span<const uuid> = {}) / bool touched_in_play(const uuid &) / span<const uuid> touched_entities() edits made while playing
result<persist_pin_result> play_controller::pin(const persist_request &) / result<usize> unpin(const persist_unpin_request &) / const persist_list &persisted() / const persist_report &last_persist_report() play-mode persist
result<json::document> play_controller::snapshot_component_json(const uuid &, string_view) / const scene_snapshot *snapshot() / u64 marker_version() the scene before play, for the UI's markers
persist_capture persist_list::capture(editor_context &, const scene_snapshot &) / static persist_report apply(editor_context &, const persist_capture &) / static persist_report drop(const persist_capture &, string_view) reading and applying the pins at a stop
edit_origin play_controller::changed_by(const persist_entry &) / void note_play_edit(const command_inverse &, const json::value &, u32) / edit_origin_scope(play_controller &, edit_origin) who changed what during play
void play_edit_log::note(editor_context &, const command_inverse &, const json::value &, edit_origin) / edit_origin changed_by(editor_context &, const persist_entry &) / string_view to_string(edit_origin) the log of play edits
bool same_as_edited(editor_context &, string_view, const json::value &, const json::value &) / bool changed_from_edited(editor_context &, string_view, const json::document &, const json::document &, string_view) / bool same_json_value(const json::value &, const json::value &) comparing a component with its form of before play
pick_result pick(const math::ray &, span<const pick_candidate>, const pick_context &, pick_mode) picking
void screenshot_service::request(const screenshot_request &, async_reply) / bool available() screenshots
optional<screenshot_format> screenshot_format_of(const path &) / parse_screenshot_format(string_view) / string_view to_string(screenshot_format) / static bool screenshot_service::supports(screenshot_format) the screenshot file format
static result<ecs::entity> entity_ref::resolve(const json::value &, scene::scene &) guid or path to entity
static result<reflection_path> reflection_path::parse(string_view) / result<json::document> read_at(...) / result<void> write_at(...) field paths

See also: