Vixenka / bevy_dev

Dev tools for Bevy Engine
https://crates.io/crates/bevy_dev
MIT License
20 stars 2 forks source link

Question about unsafe #4

Open TheButlah opened 1 month ago

TheButlah commented 1 month ago

Hi, what is the purpose of the unsafe code here? I didn't understand why #[derive(Bundle)] is insufficient.

Vixenka commented 1 month ago

Hi @TheButlah, this unsafe code is required here, because #[derive(Bundle)] trait requires for every field to implement a Component trait, but PrototypeMaterialMeshBundle have field what is a &'static str which contain a feature name like floor. And only when adding components to entity, this text value is changed to their component representation. I made that for simplicity of usage.

Aceeri commented 3 weeks ago

Hi @TheButlah, this unsafe code is required here, because #[derive(Bundle)] trait requires for every field to implement a Component trait, but PrototypeMaterialMeshBundle have field what is a &'static str which contain a feature name like floor. And only when adding components to entity, this text value is changed to their component representation. I made that for simplicity of usage.

What do you think of using Name directly for these color generations? Those should be pretty much stable across runs in games, plus adds the benefit of not having to worry too much about the PrototypeMaterialMeshBundle as a user.

Vixenka commented 2 weeks ago

@Aceeri hmm, Name looks like a fine idea to apply that color, but still I think overriding this color by component will be useful. And about stability, then two of them should work stable.