Editor Features from Code
Everything the editor does that a plugin can hook into, and the call that hooks into it. Editor Panels covers drawing UI; this page covers behaviour: the registries a plugin writes into to add inspector sections, spawn entries, shortcuts, viewport tools, context menu rows and Console output, plus the shared state every plugin reads.
All of it is in the contract. A native plugin reaches it through renzora (the editor contract is flat at the root: renzora::EditorSelection, renzora::AppEditorExt); an in-workspace editor crate depends on renzora_editor_api and renzora_shell_api directly. Most registrations are methods on App from two traits:
use renzora::AppEditorExt; // inspector, presets, tools, shortcuts, icons
use renzora::core::RenzoraShellExt; // panels, status bar, top-bar buttons
A registration is a build-time act: call it from your plugin's build. Nothing is ever unregistered, because Bevy cannot withdraw what a plugin added and a native plugin's image is never unmapped. Everything on this page is editor-only, so in a native plugin with Runtime scope it belongs in the editor half (src/editor.rs); see Native Plugins.
Selection
EditorSelection is the resource everything in the editor agrees on. It uses interior mutability, so Res<EditorSelection> is enough to change it.
use renzora::EditorSelection;
fn my_system(selection: Res<EditorSelection>, q: Query<&Name>) {
for e in selection.get_all() {
if let Ok(name) = q.get(e) {
info!("selected: {name}");
}
}
}
| Method | |
|---|---|
get() -> Option<Entity> | the primary (last clicked) selection |
get_all() -> Vec<Entity> | everything selected, in click order |
set(Option<Entity>) | replace the selection |
set_multiple(Vec<Entity>) | replace with many |
toggle(Entity) | add or remove one (Ctrl+click) |
select_range(&visible_order, anchor, target) | Shift+click; you supply the display order |
is_selected(Entity), has_multi_selection() | |
clear() | |
version() -> u64 | bumps on every change: a cheap dirty check |
Play mode
PlayModeState says what the editor is doing, and the distinctions matter:
| Method | True when |
|---|---|
is_editing() | stopped |
is_playing() / is_paused() | play mode |
is_simulating() | Simulate: the scene runs, editor tooling stays live |
is_in_play_mode() | playing or paused; excludes Simulate |
is_scripts_running() | playing or simulating |
Use is_in_play_mode() to decide whether to hide editor tooling, since Simulate must keep it. Use is_scripts_running() to decide whether gameplay logic should tick. Ready-made run conditions: not_in_play_mode, game_running, and in_three_view / in_two_view for visuals that only make sense through one camera.
app.add_systems(Update, my_gizmo_system.run_if(renzora::core::not_in_play_mode));
The inspector
Declarative fields
Register a component and the inspector builds its section: a header with your icon, one row per field, with drag values, colour pickers and asset slots chosen from the field types. This is crates/renzora_oit/editor, complete:
use bevy::prelude::*;
use renzora_editor_api::{AppEditorExt, InspectorEntry};
use renzora_oit::OitSettings;
fn oit_entry() -> InspectorEntry {
InspectorEntry {
type_id: "oit",
display_name: "OIT Transparency",
icon: "stack",
category: "rendering",
has_fn: |world, entity| world.get::<OitSettings>(entity).is_some(),
add_fn: Some(|world, entity| {
world.entity_mut(entity).insert(OitSettings::default());
}),
remove_fn: Some(|world, entity| {
world.entity_mut(entity).remove::<OitSettings>();
}),
is_enabled_fn: Some(|world, entity| {
world.get::<OitSettings>(entity).map(|s| s.enabled).unwrap_or(false)
}),
set_enabled_fn: Some(|world, entity, val| {
if let Some(mut s) = world.get_mut::<OitSettings>(entity) {
s.enabled = val;
}
}),
fields: vec![
renzora_editor_api::int_field!("Layers", OitSettings, layer_count, i32, 1.0, 1.0, 32.0),
renzora_editor_api::float_field!("Alpha Threshold", OitSettings, alpha_threshold, 0.01, 0.0, 1.0),
],
}
}
#[derive(Default)]
pub struct OitEditorPlugin;
impl Plugin for OitEditorPlugin {
fn build(&self, app: &mut App) {
app.register_inspector(oit_entry())
.inspector_reads::<OitSettings>("oit");
}
}
add_fn: None keeps the component out of Add Component; remove_fn: None hides the section's remove control. is_enabled_fn and set_enabled_fn together give the section a toggle.
The field macros (float_field!, int_field!, bool_field!, string_field!, color_rgba_field!, vec3_color_field!, tuple_color_field!, enum_u32_field!) build a FieldDef for one component field. Written by hand, a FieldDef is a name, a field_type, and a get_fn: fn(&World, Entity) -> Option<FieldValue> / set_fn: fn(&mut World, Entity, FieldValue) pair; FieldDef::group and FieldDef::toggle_group nest rows.
The field types: Float { speed, min, max }, Int { min, max }, Vec3 { speed }, Bool, Color, ColorRgba, String, ReadOnly, Asset { extensions }, AssetCreatable { extensions, create_fn }, Enum { options }, DynamicEnum { options }, CheckedEnum { options, warning }, Button { icon } and Group { fields }. Three have traps:
Intis not cosmetic. Aset_fnthat rounds into an integer must pair withFieldType::Int, or the widget's fractional drag and your rounded re-read fight and the value stutters mid-drag.Buttonhas no value. Itsget_fnreturnsNone, and a click callsset_fnwithFieldValue::Bool(true).DynamicEnumspeaks indices, not labels (FieldValue::Float(index)), which is what makes it keyframeable.CheckedEnumis anEnumwhosewarningfunction can mark individual options with a reason, re-asked every frame.
category is the Inspector page the section appears on, and its group in Add Component:
category | Page |
|---|---|
"object" | Object: Transform and anything describing the entity itself |
"rendering" | Rendering: meshes, materials, decals, text, sprites |
"lighting" | Lighting |
"camera" | Camera and its image effects (offered in Add Component only on a camera) |
"environment" | Environment: sky, atmosphere, fog, terrain |
"post_process" | Post Process |
"physics" | Physics |
"animation" | Animation |
"scripting" | Scripting |
"audio" | Audio |
"navigation" | Navigation |
"networking" | Networking |
"ui" | UI (offered only inside a UI canvas) |
"particles" | Particles |
Older names still land sensibly ("light", "postprocess", "gameplay", "multiplayer", "effects", "sound", "material", and so on); anything unrecognised goes to Object. The mapping is InspectorPage::for_entry in renzora_shell_api.
app.inspector_reads::<C>(type_id) declares that a section's own fields read component C on the inspected entity, so their bindings run only when it changes instead of every frame. Declare it only when no field reads a resource, an asset or another entity. See Inspector Fields.
app.extend_inspector(type_id, fields) adds rows to a section another crate owns, without that crate depending on yours. A row with a name already there replaces it.
register_inspectable::<T>() is the shortcut for a component that derives Inspectable (#[inspectable(name = "...", icon = "...", category = "...")] on the type, #[field(name = "...", speed = ..., min = ..., max = ...)], skip or readonly on fields). It registers the type for reflection, the generated entry and the inspector_reads declaration in one call.
Custom drawers
When declarative fields are not enough (conditional rows, a custom widget), register a drawer. It gets &mut World and returns the root of a bevy_ui subtree built with ember:
app.register_native_inspector_ui("my_glow", |world, entity| {
// build rows, return the root Entity
world.spawn(Node::default()).id()
});
The type_id must match a registered InspectorEntry. The drawer replaces the field rows; the section header stays.
Spawning
Entity presets
An entry in the Hierarchy's spawn menu:
use renzora::EntityPreset;
app.register_entity_preset(EntityPreset {
id: "my_plugin.beacon",
display_name: "Beacon",
icon: "lighthouse",
category: "Lights",
spawn_fn: |world| world.spawn((Name::new("Beacon"), Transform::default(), Beacon)).id(),
});
Give what you spawn a Name: the Hierarchy lists (Entity, &Name), so an unnamed entity has no row, cannot be selected and is not saved.
Scene starters
The cards on the Hierarchy's empty-scene picker:
use renzora::SceneStarter;
app.register_scene_starter(SceneStarter {
id: "my_plugin.arena",
title: "Arena",
description: "A floor, four walls and a camera.",
icon: "cube",
produces: &[],
spawn_fn: |world| { /* spawn as much as you like */ },
});
produces lists the component type names the starter creates, matched against the Hierarchy's filter. Empty means "a whole scene", and such a starter is offered only while the Hierarchy is unfiltered (the UI workspace, which shows only UiCanvas, does not offer New Environment). spawn_fn may spawn any number of entities or insert resources. Registering an existing id again is ignored.
Adding to a new World Environment
When the editor spawns a World Environment (the preset or the New Environment starter), it triggers WorldEnvironmentSpawned on the new entity. Observe it to add your part of the sky without the preset naming you:
app.add_observer(|spawned: On<renzora::WorldEnvironmentSpawned>, mut commands: Commands| {
commands.entity(spawned.entity).insert(MyHaze::default());
});
outdoor_daylight is set for the starter's clear mid-morning look, so a component with a look of its own can match it. Loading a scene does not fire it.
Hierarchy icons
use renzora::ComponentIconEntry;
app.register_component_icon(ComponentIconEntry {
type_id: std::any::TypeId::of::<Beacon>(),
name: "Beacon",
icon: "lighthouse",
color: [255, 200, 120],
priority: 10,
dynamic_icon_fn: None,
});
priority breaks ties when an entity carries several registered components (higher wins). name is what the Hierarchy's filter by type shows. dynamic_icon_fn lets the icon depend on the entity's state.
Context menu rows
Three menus take rows from plugins, each through the same pattern: an id, a label as a translation key with fallback text, an icon, and a test for where it applies. Registering an id again replaces the earlier row.
Hierarchy rows (renzora::EntityAction):
use renzora::{EntityAction, RegisterEntityAction};
app.register_entity_action(
EntityAction::new("light_beacons", |world, clicked| {
// act on `clicked`, or on the EditorSelection when `clicked` is part of it
})
.label("hierarchy.action.light_beacons", "Light beacons")
.icon("lighthouse")
.applies_to(|world, entity| world.get::<Beacon>(entity).is_some()),
);
Assets panel rows (renzora::AssetAction), for one kind of file or for a folder holding that kind:
use renzora::{AssetAction, AssetActionScope, RegisterAssetAction};
app.register_asset_action(
AssetAction::new("bake_lut", AssetActionScope::File, &["cube"], |world, path| {
// `path` is absolute
})
.label("assets.action.bake_lut", "Bake LUT")
.icon("palette"),
);
A Folder action is offered on a folder only when it directly holds at least one matching file.
New file entries (renzora::CreateMenuItem), in the Assets panel's Add menu and the Hierarchy's Attach menu: CreateMenuItem::new(id, stem, extension, starter) where starter produces the new file's text, with .label, .subtitle, .icon, .folder (the default destination), .attaches() (offered on an entity) and .opens(fn) (open a dialog instead of writing the starter). Register with register_create_menu_item. A file type exists in these menus exactly when the plugin that understands it is installed.
Accepting files dragged from the Assets panel
While a file is dragged out of the Assets panel the editor holds a renzora::AssetDragPayload resource: the dragged paths, and is_detached once the pointer has moved far enough to count as a drag. Put renzora::ui::UiCursor on the node that accepts drops, and on the frame the left button is released take the paths if the pointer is over it:
use renzora::AssetDragPayload;
use renzora::ui::UiCursor;
#[derive(Component)]
struct MyDropZone;
fn accept_drop(
mouse: Res<ButtonInput<MouseButton>>,
payload: Option<Res<AssetDragPayload>>,
zones: Query<&UiCursor, With<MyDropZone>>,
) {
if !mouse.just_released(MouseButton::Left) {
return;
}
let Some(payload) = payload.filter(|p| p.is_detached) else { return };
if !zones.iter().any(|c| c.cursor_over()) || !payload.matches_extensions(&["png"]) {
return;
}
for path in &payload.paths {
// an absolute path inside the project
}
}
The Assets panel removes the resource that frame through Commands, so every system in the frame still sees it.
Keyboard shortcuts
use renzora::ShortcutEntry;
use renzora::core::keybindings::KeyBinding;
app.register_shortcut(ShortcutEntry::new(
"my_plugin.snap_all",
"Snap Selection to Ground",
"Transform",
KeyBinding::new(KeyCode::KeyG).ctrl().shift(),
|world| { /* &mut World */ },
));
The binding is a default. It is seeded into KeyBindings::plugin_bindings under your id and appears in Settings under your category, where the user can rebind it; after that your default is never consulted. Keep the id stable across releases, or everyone's rebind is orphaned. Use an existing category to group with the built-ins, or any string of your own.
Taking the keyboard from the shortcuts
A panel that reads raw keystrokes has to stop the editor's shortcuts firing while the user types:
fn claim_keyboard(mine: Res<MyPanelState>, focus: Option<ResMut<renzora::InputFocusState>>) {
if mine.focused {
if let Some(mut focus) = focus {
focus.plugin_wants_keyboard = true;
}
}
}
plugin_wants_keyboard is a claim re-made every frame: the editor folds it into the flag every shortcut, the gizmo keys and the camera's WASD already check, then clears it. Raise it for as long as you want the keys. That shape is what makes it safe: several plugins can hold a claim without clearing each other's, and a panel that stops running releases the keyboard by itself. Register the claiming system through the panel's gated .systems, not .always, or a hidden panel keeps the keyboard.
Viewport tools
A tool is a button with predicates for visibility and active state:
use renzora::{ToolEntry, ToolSection};
app.register_tool(
ToolEntry::new("my_plugin.paint", "paint-brush", "Paint (B)", ToolSection::Shelf("myplugin.a-paint"))
.order(10)
.visible_if(|world| world.get_resource::<MyMode>().is_some())
.active_if(|world| world.resource::<MyMode>().painting)
.on_activate(|world| world.resource_mut::<MyMode>().painting = true),
);
ToolSection | Where |
|---|---|
Transform | the leading section of the toolbar strip (no built-in tool uses it now) |
Terrain | the context-sensitive terrain group, shown while a terrain is selected |
Custom(key) | a plugin group on the strip, grouped by key |
Shelf(group) | the vertical two-column shelf on the viewport's left edge, where the built-in select, move, rotate and scale gizmos live |
The two surfaces split by depth. A tool that opens a set of other tools stays on the strip, so one row always says what the viewport is set to do; what you actually hold (brushes, select modes, ops) goes on the shelf, which grows downwards instead of wrapping the strip. Hide shelf tools with visible_if while their mode is off.
Shelf groups render alphabetically by group string, globally across all crates. A toolset whose groups must hold a fixed order encodes it in the id, as terrain does: terrain.a-sculpt, terrain.b-paint, and so on.
on_activate runs as a deferred editor command, so it gets &mut World safely. An active tool is drawn with an accent fill; a toggle, which is simply on rather than chosen from a group, asks for .active_style(ToolActiveStyle::Tint).
ToolEntry gives a standard icon button with the editor's own arrangement. The ember toolbar functions give a blank slate for controls a button cannot express.
Hierarchy footer buttons
use renzora::{place_above_selection, EditorSelection, HierarchyFooterButton, HierarchyRenameRequest};
app.register_hierarchy_footer_button(
HierarchyFooterButton::new("my_plugin.new_marker", "map-pin", "New Marker")
.order(20)
.visible_if(|world| world.get_resource::<MyMode>().is_some())
.on_activate(|world| {
let e = world.spawn((Name::new("marker"), Transform::default(), Visibility::default())).id();
place_above_selection(world, e);
if let Some(sel) = world.get_resource::<EditorSelection>() {
sel.set(Some(e));
}
HierarchyRenameRequest::request(world, e);
}),
);
Buttons sit left to right by order; the built-ins use 0, 100 and 1000. visible_if is asked every frame. Something created from the footer goes where the user is looking:
| Function | Puts new |
|---|---|
place_above_selection(world, new) | directly above the primary selection, in its parent; at the top of the scene with nothing selected |
place_above(world, new, Some(anchor)) | directly above anchor (None: the top of the scene) |
place_first_in(world, new, Some(parent)) | first among parent's children (None: the top of the scene) |
HierarchyRenameRequest::request(world, entity) opens the inline rename, as a double-click does.
Console output
The Console reads a process-global buffer, so a plugin logs into it with a plain function call:
use renzora::core::console_log::{console_info, console_warn};
console_info("my-plugin", "scanned 412 meshes");
console_warn("my-plugin", format!("{n} meshes have no UVs"));
The first argument is the category the Console filters by: use one stable string per plugin. console_error and console_success complete the set, and the clog_info! / clog_warn! / clog_error! / clog_success! macros take format arguments. Bevy's own info! / warn! / error! also reach the Console, with the module path as the category.
Content problems
The Problems panel is fed by the ContentProblems resource, keyed by project-relative path:
use renzora::content_problems::{ContentProblem, ContentProblems, ProblemSeverity};
fn report(mut problems: ResMut<ContentProblems>) {
problems.set(
"models/tree.glb",
vec![ContentProblem {
severity: ProblemSeverity::Warning,
message: "no UVs".into(),
line: None,
node_id: None,
}],
);
}
set replaces everything recorded for the path, so a re-validation never stacks duplicates; clear_path removes it, and error_count() / warning_count() drive the panel's badge.
Translations
Every user-visible string should go through the shared translation table (renzora::lang::t, t_or, t_args). A missing key returns the key itself rather than an error. See Localization.
Project and lifecycle
CurrentProject | the open project: paths and settings |
SplashState | the boot state machine; OnEnter(SplashState::Editor) is where a plugin spawns scene content |
SaveSceneRequested | ask the editor to save the open scene |
Spawn on OnEnter(SplashState::Editor), not Startup. The project-load teardown despawns named entities after Startup.
Undoable edits
Implement UndoCommand and hand it to execute. The trait and the stacks are in the contract so a plugin pushes onto the same history Ctrl+Z reads.
use renzora::undo::{execute, UndoCommand, UndoContext};
struct TintEdit { entity: Entity, before: Color, after: Color }
impl UndoCommand for TintEdit {
fn label(&self) -> &str { "tint" }
fn execute(&mut self, world: &mut World) { write_tint(world, self.entity, self.after); }
fn undo(&mut self, world: &mut World) { write_tint(world, self.entity, self.before); }
}
execute(world, UndoContext::Scene, Box::new(TintEdit { entity, before, after }));
execute applies the command and records it; record only records, for a change that already happened. merge (default false) lets a drag collapse into one step. UndoContext::MaterialGraph(path) keeps an edit on that graph's own history. Never define a private copy of the trait or the stacks: it would push onto a history Ctrl+Z never reads, so the edit would look undoable and not be. See Undo.
Moving the viewport camera
Insert a renzora::CameraViewRequest. It is one-shot: the camera controller applies and removes it on the same frame.
use renzora::CameraViewRequest;
world.insert_resource(CameraViewRequest::LookAt {
eye: Vec3::new(15.0, 11.0, 15.0),
target: Vec3::ZERO,
});
world.insert_resource(CameraViewRequest::Frame(entity)); // as the F key does
The set is ZoomIn, ZoomOut, ResetZoom, FrameAll, Frame(Entity), LookAt { eye, target } and SetOrbit { .. }. Do not write the editor camera's Transform: the controller recomputes it from its orbit state every frame, so the write silently disappears. Requests are ignored during play, where the game owns the camera.
GPU pass attribution
A plugin that adds a render pass can tell the GPU Pass Breakdown what drives it:
app.register_gpu_pass_source::<MyEffect>("my_effect_", "effect");
Every pass whose name starts with my_effect_ is then attributed to the live entities carrying MyEffect, labelled with that noun.
See also
- Editor Panels: the UI half
- Native Plugins: building and loading
- Inspector Fields: the
Inspectablederive in depth - Post-Processing Effects: fullscreen effects need no plugin at all