Crate bevy_inspector_egui
source ·Expand description
This crate contains
- general purpose machinery for displaying
Reflect
values inreflect_inspector
, - a way of associating arbitrary options with fields and enum variants in
inspector_options
- utility functions for displaying bevy resource, entities and assets in
bevy_inspector
- some drop-in plugins in
quick
to get you started without any code necessary.
§Use case 1: Quick plugins
These plugins can be easily added to your app, but don’t allow for customization of the presentation and content.
§WorldInspectorPlugin
Displays the world’s entities, resources and assets.
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::new())
.run();
}
§ResourceInspectorPlugin
Display a single resource in a window.
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(ResourceInspectorPlugin::<Configuration>::default())
// also works with built-in resources, as long as they implement `Reflect`
.add_plugins(ResourceInspectorPlugin::<Time>::default())
.run();
}
There is also the StateInspectorPlugin
and the AssetInspectorPlugin
.
§Use case 2: Manual UI
The quick
plugins don’t allow customization of the egui window or its content, but you can easily build your own UI:
use bevy::prelude::*;
use bevy_egui::{EguiPlugin, EguiContext};
use bevy_inspector_egui::prelude::*;
use bevy_inspector_egui::bevy_inspector;
use bevy_window::PrimaryWindow;
use std::any::TypeId;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s
.add_systems(Update, inspector_ui)
.run();
}
fn inspector_ui(world: &mut World) {
let mut egui_context = world
.query_filtered::<&mut EguiContext, With<PrimaryWindow>>()
.single(world)
.clone();
egui::Window::new("UI").show(egui_context.get_mut(), |ui| {
egui::ScrollArea::both().show(ui, |ui| {
// equivalent to `WorldInspectorPlugin`
bevy_inspector::ui_for_world(world, ui);
// works with any `Reflect` value, including `Handle`s
let mut any_reflect_value: i32 = 5;
bevy_inspector::ui_for_value(&mut any_reflect_value, ui, world);
egui::CollapsingHeader::new("Materials").show(ui, |ui| {
bevy_inspector::ui_for_assets::<StandardMaterial>(world, ui);
});
ui.heading("Entities");
bevy_inspector::ui_for_world_entities(world, ui);
});
});
}
Pair this with a crate like egui_dock
and you have your own editor in less than 100 lines: examples/egui_dock.rs
.
§FAQ
Q: How do I change the names of the entities in the world inspector?
A: You can insert the Name
component.
Q: What if I just want to display a single value without passing in the whole &mut World
?
A: You can use ui_for_value
. Note that displaying things like Handle<StandardMaterial>
won’t be able to display the asset’s value.
Q: Can I change how exactly my type is displayed?
A: Implement InspectorPrimitive
and call app.register_type_data::<T, InspectorEguiImpl>
.
Re-exports§
Modules§
- Methods for displaying
bevy
resources, assets and entities - Custom UI implementations for specific types. Check
InspectorPrimitive
for an example. - Way of associating options to fields using
InspectorOptions
- Reexports of commonly used types
- Easy plugins for showing UI panels.
- A view into the world which may only access certain resources and components
Structs§
- Map of
Target
s to arbitraryTypeData
used to control how the value is displayed, e.g.NumberOptions
.
Derive Macros§
- Derive macro used to derive
InspectorOptions