jakobhellermann / bevy-inspector-egui

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

Optional Enum in Struct won't compile #129

Closed teken closed 1 year ago

teken commented 1 year ago

I have a struct:

#[derive(Clone, Debug, PartialEq, Reflect)]
pub struct Item {
    pub material: Option<Material>,
    pub energy: Option<Energy>,
    pub quantity: f32,
}

Both Material and Energy are enums with the same derives, yet it shows this error

error[E0277]: the trait bound `materials::Material: FromReflect` is not satisfied
  --> src\materials.rs:51:35
   |
51 | #[derive(Clone, Debug, PartialEq, Reflect)]
   |                                   ^^^^^^^ the trait `FromReflect` is not implemented for `materials::Material`
   |
   = help: the following other types implement trait `FromReflect`:
             &'static std::path::Path
             ()
             (A, B)
             (A, B, C)
             (A, B, C, D)
             (A, B, C, D, E)
             (A, B, C, D, E, F)
             (A, B, C, D, E, F, G)
           and 208 others
   = note: required for `std::option::Option<materials::Material>` to implement `bevy::prelude::Reflect`
   = help: see issue #48214
   = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)
StatisMike commented 1 year ago

Do Material and Energy have derived FromReflect, per the error message?

jakobhellermann commented 1 year ago

yeah, you need #[derive(FromReflect)] struct T for Option<T>: https://github.com/bevyengine/bevy/blob/253db50c63a236e7928f6dc83e99843d4edc8f68/crates/bevy_reflect/src/impls/std.rs#L722

teken commented 1 year ago

wow im an idiot, thank you