Implement custom UI via InspectorEguiImpl
mainInspectableRegistry, you should now add InspectorEguiImpl type data to the Bevy TypeRegistry for that specific type.repository·main·Indexed 23 days ago
https://github.com/jakobhellermann/bevy-inspector-eguiAn inspector plugin for the Bevy game engine using the egui library. It provides tools for inspecting Bevy worlds, resources, entities, and assets through high-level 'quick' plugins (such as WorldInspectorPlugin and ResourceInspectorPlugin) or low-level APIs for building custom editor interfaces. Features include the InspectorOptions derive macro for UI tweaking, the InspectorPrimitive trait for custom type representations, and support for entity hierarchy visualization.
InspectableRegistry, you should now add InspectorEguiImpl type data to the Bevy TypeRegistry for that specific type.To change the names of entities displayed in the world inspector, insert the Name component onto the entity.
To display a single value without passing the entire &mut World, use reflect_inspector::ui_for_value. Note that handles (e.g., Handle<StandardMaterial>) will not be able to display the underlying asset's value using this method.
To change how a specific type is displayed, implement the InspectorPrimitive trait and register it using:
app.register_type_data::<T, InspectorEguiImpl>().
The quick::WorldInspectorPlugin provides a ready-to-use UI that displays the Bevy world's entities, resources, and assets. This is ideal for simple use cases where you don't need to customize the presentation.
Note: You must also include EguiPlugin from bevy_egui for the inspector to render.
use bevy::prelude::*;
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin::default())
.add_plugins(WorldInspectorPlugin::new())
.run();
}The quick::ResourceInspectorPlugin displays a specific Bevy resource in its own window.
To use it:
Reflect and Resource for your type.InspectorOptions to add constraints (like min or max) to fields.app.register_type::<T>().ResourceInspectorPlugin::<T>::default().Note: The plugin does not initialize the resource itself; you must use app.init_resource::<T>() or similar.
use bevy::prelude::*;
use bevy_inspector_egui::prelude::*;
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
// `InspectorOptions` are completely optional
#[derive(Reflect, Resource, Default, InspectorOptions)]
#[reflect(Resource, InspectorOptions)]
struct Configuration {
name: String,
#[inspector(min = 0.0, max = 1.0)]
option: f32,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<Configuration>() // `ResourceInspectorPlugin` won't initialize the resource
.register_type::<Configuration>() // you need to register your type to display it
.add_plugins(EguiPlugin::default())
.add_plugins(ResourceInspectorPlugin::<Configuration>::default())
// also works with built-in resources, as long as they are `Reflect`
.add_plugins(ResourceInspectorPlugin::<Time>::default())
.run();
}InspectorQuery type has been removed. To display all entities that match a specific query, use the FilterQueryInspectorPlugin instead. For example, to show all entities with a Transform component, add the plugin with a With<Transform> filter.If the quick plugins are too restrictive, you can build a custom UI by calling low-level inspector functions within your own egui windows.
To do this:
bevy_inspector_egui::DefaultInspectorConfigPlugin to your app to register default options and implementations.EguiPrimaryContextPass.EguiContext from the world.bevy_inspector_egui::bevy_inspector such as:ui_for_world(world, ui): Displays entities, resources, and assets.ui_for_assets::<T>(world, ui): Displays assets of type T.ui_for_world_entities(world, ui): Displays only entities.use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use bevy_inspector_egui::prelude::*;
use std::any::TypeId;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin::default())
.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s
.add_systems(EguiPrimaryContextPass, inspector_ui)
.run();
}
fn inspector_ui(world: &mut World) {
let Ok(egui_context) = world
.query_filtered::<&mut EguiContext, With<PrimaryEguiContext>>()
.get_single(world)
else {
return;
};
let mut egui_context = egui_context.clone();
egui::Window::new("UI").show(egui_context.get_mut(), |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
// equivalent to `WorldInspectorPlugin`
bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui);
egui::CollapsingHeader::new("Materials").show(ui, |ui| {
bevy_inspector_egui::bevy_inspector::ui_for_assets::<StandardMaterial>(world, ui);
});
ui.heading("Entities");
bevy_inspector_egui::bevy_inspector::ui_for_world_entities(world, ui);
});
});
}InspectorOptions derive macro from bevy-inspector-egui-derive to tweak how specific fields or types are rendered in the inspector UI. This allows you to control the visual representation and behavior of your data within the inspector windows.In versions 0.16 and later, InspectorPlugin has been renamed to ResourceInspectorPlugin and moved to the quick module.
Key changes:
App.Reflect on your types instead of Inspectable..register_type::<T>() in your Bevy app setup.You can integrate the inspector into complex UI architectures:
egui_dock integration pattern to build a multi-window editor environment (e.g., combining bevy-inspector-egui with egui_gizmo).side_panel.rs pattern to embed inspector elements into specific parts of your application's UI layout, such as a side panel.In versions 0.16 and later, WorldInspectorPlugin has been moved to quick::WorldInspectorPlugin.
Note: WorldInspectorParams has been removed. If you previously used this to customize the plugin, you should now copy the implementation of WorldInspectorPlugin and modify it to suit your needs.
For full control over the layout and content of your debugging tools, you can build manual inspector windows instead of using high-level plugins.
resource_inspector_manual.rs pattern.bevy_inspector::ui_for_world function.InspectorPrimitive trait. This allows you to define exactly how egui should render and interact with your type.