jakobhellermann / bevy-inspector-egui

Inspector plugin for the bevy game engine
Apache License 2.0
1.12k stars 166 forks source link

"You should register ReflectDefault for all fields" error message is still unclear #136

Closed ProgrammerPeter2 closed 1 year ago

ProgrammerPeter2 commented 1 year ago

I have an enum resource with structs in it, but when I want to change the variant I have the following error message: " TransitionType has unconstructable variants: Cross Dissolve, you should register ReflectDefault for all fields.". ReflectDefault is a struct so I can't implement it to my config. I saw #116, but something still in darkness in front of me: where should I add the #[reflect(Default)] attribute to work?

My code

lib.rs

mod angled;
mod dissolve;

#[derive(Clone, Copy,Resource, Reflect,FromReflect)]
#[reflect(Resource, Default)]
pub enum TransitionType {
    Angled(AngledTransConfig),
    CrossDissolve(CrossDissolveConfig)
}

angled.rs

#[derive(Clone, Copy, Resource, FromReflect, Reflect)]
#[reflect(Resource)]
pub struct AngledTransConfig {
    pub(crate) angle: f32,
    pub(crate) x_cut: i32
}

impl Default for AngledTransConfig {
    fn default() -> Self {
        Self {
            angle: 0.0,
            x_cut: 0
        }
    }
}

dissolve.rs

#[derive(Clone, Copy, Resource, FromReflect, Reflect)]
#[reflect(Resource)]
pub struct CrossDissolveConfig {
    pub(crate) progress: f32
}

impl Default for CrossDissolveConfig {
    fn default() -> Self {
        Self { progress: 0.0}
    }
}
jakobhellermann commented 1 year ago

The error is that I can't create an instance of TransitionType::CrossDissolve because the code has no idea how to create CrossDissolveConfig.

The the solution would be to add

#[derive(Clone, Copy, Resource, FromReflect, Reflect, Default)]
#[reflect(Resource, Default)]
pub struct CrossDissolveConfig {}

app.register_type::<CrossDissolveConfig>();

image

Would this error message be clear enough or do you have suggestions for how to make it better?

ProgrammerPeter2 commented 1 year ago

Yes, this will be clear enough.