jakobhellermann / bevy_editor_pls

In-App editor tools for bevy applications
Other
758 stars 78 forks source link

Resources missing from resource panel #94

Closed blueforesticarus closed 9 months ago

blueforesticarus commented 9 months ago

I can't seem to figure out how to get my custom resource to show up in the panel. I've tried deriving Reflect based on reading the resource panel code, but to no avail.

What I have:

use bevy::prelude::*;
use bevy_editor_pls::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EditorPlugin::default())
        .add_systems(Startup, setup)
        .add_systems(Update, keyboard_input_system)
        //.init_resource::<Speed>()
        .insert_resource(Speed { s: 0.5 })
        .run();
}

#[derive(Resource, Reflect, Debug, Clone, Copy)]
pub struct Speed {
    pub s: f32,
}

...

But Speed still does not show up in the resource panel.

jakobhellermann commented 9 months ago

You're missing app.register_type::<Speed>(). Also I think the inspector only shows types that have #[reflect(Resource)] below the derive but I'm not 100% sure right now.

blueforesticarus commented 9 months ago

Yup. Needed both of those. Gracias

Working:

use bevy::prelude::*;
use bevy_editor_pls::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EditorPlugin::default())
        .add_systems(Startup, setup)
        .add_systems(Update, keyboard_input_system)
        //.init_resource::<Speed>()
        .insert_resource(Speed { s: 0.5 })
        .register_type::<Speed>() //HERE
        .run();
}

#[derive(Resource, Reflect)]
#[reflect(Resource)] //HERE
pub struct Speed {
    pub s: f32,
}
blueforesticarus commented 9 months ago

semi-relevant open bevy issue https://github.com/bevyengine/bevy/issues/3936

jakobhellermann commented 9 months ago

Also I think bevy_inspector_egui could technically display all registered resources, regardless of whether they have reflect(Resource). I'm not sure if that would be better, maybe it's good to be explicit about that, and I think things like resources in scenes need it.