Crate bevy_inspector_egui
source ·Expand description
This crate provides the ability to annotate structs with a #[derive(Inspectable)]
,
which opens a debug interface using egui where you can visually edit the values of your struct live.
Your struct will then be available to you as a bevy resource.
Example
use bevy_inspector_egui::Inspectable;
#[derive(Resource, Inspectable, Default)]
struct Data {
should_render: bool,
text: String,
#[inspectable(min = 42.0, max = 100.0)]
size: f32,
}
Add the InspectorPlugin
to your App.
use bevy_inspector_egui::InspectorPlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InspectorPlugin::<Data>::new())
.run();
}
The list of built-in attributes is documented here.
World Inspector
If you want to display all world entities you can add the WorldInspectorPlugin
:
use bevy::prelude::*;
use bevy_inspector_egui::WorldInspectorPlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::new())
.add_startup_system(setup)
.run();
}
You can configure the WorldInspectorPlugin
by inserting the WorldInspectorParams
resource.
If you want to only display some components, you may want to use the InspectorQuery instead.
Custom components in the world inspector
By default, types implementing Inspectable
will not be displayed in the WorldInspector
, because the there is no way to know of the trait implementation at runtime.
You can call app.register_inspectable::<T>()
to tell bevy-inspector-egui
how that type should be displayed, and it will show up correctly in the world inspector.
Alternatively, you can #[derive(Reflect)]
and call app.register_type::<T>()
. This will enable bevy’s reflection feature for the type, and it will show up in the world inspector.
use bevy::prelude::*;
use bevy_inspector_egui::{WorldInspectorPlugin, Inspectable, RegisterInspectable};
#[derive(Inspectable, Component)]
struct InspectableType;
#[derive(Reflect, Component, Default)]
#[reflect(Component)]
struct ReflectedType;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::new())
.register_inspectable::<InspectableType>() // tells bevy-inspector-egui how to display the struct in the world inspector
.register_type::<ReflectedType>() // registers the type in the `bevy_reflect` machinery, so that even without implementing `Inspectable` we can display the struct fields
.run();
}
Features
- clipboard (enabled by default): enables
egui
’s clipboard integratoin
Re-exports
pub use bevy_egui;
pub use bevy_egui::egui;
Modules
Inspectable
implementationsInspectable
implementation for foreign types implementing Reflect
Inspectable
WorldInspectorPlugin
Structs
Inspectable::ui
.InspectableRegistry
can be used to tell the WorldInspectorPlugin
how to display a type.Traits
app.register_inspectable::<T>()
Derive Macros
Inspectable
trait.