bevy-inspector-egui icon indicating copy to clipboard operation
bevy-inspector-egui copied to clipboard

`InspectorQuery::<T>` does not apply mutations

Open djeedai opened this issue 3 years ago • 2 comments

This was already broken for me in 0.8.0, and still in 0.8.1.

Any of these forms work as expected:

.add_plugin(WorldInspectorPlugin::new())
// OR
.add_plugin(InspectorPlugin::<InspectorQuerySingle<Entity, With<Animator<Transform>>>>::new())

But this form produces an inspector that, when a value is mutated (here, the Animator<T>::state field), does not mutate the target component:

.add_plugin(InspectorPlugin::<Animator<Transform>>::new())

The generic Animator<T> is defined as:

#[derive(Component)]
#[cfg_attr(feature = "bevy_inspector_egui", derive(Inspectable))]
pub struct Animator<T: Component> {
    pub state: AnimatorState, // some Inspectable-derived C-style enum
    #[cfg_attr(feature = "bevy_inspector_egui", inspectable(ignore))]
    prev_state: AnimatorState,
    #[cfg_attr(feature = "bevy_inspector_egui", inspectable(ignore))]
    tweenable: Option<Box<dyn Tweenable<T> + Send + Sync + 'static>>,
}

...and the bevy_inspector_egui feature is used.

djeedai avatar Feb 12 '22 18:02 djeedai

The InspectorPlugin<T> will insert and edit T as a resource, not for components.

So if you want to edit one component of a single entity, you should use .add_plugin(InspectorPlugin::<InspectorQuerySingle<&'static mut Animator<Transform>>>::new()).

jakobhellermann avatar Feb 13 '22 11:02 jakobhellermann

Ah good to know, I didn't know about the resource vs. component distinction. Maybe it's worth calling out in the README, where InspectorPlugin<T> is immediately pointed in the Usage section but without that clarification?

djeedai avatar Feb 13 '22 21:02 djeedai

InspectorQuery doesn't exist anymore, so fixed.

but it is now easy to do it yourself:

let mut query = world.query_filtered::<Entity, With<Animator<Transform>>>();
for entity in query.iter(world) {
      bevy_inspector_egui::bevy_inspector::ui_for_entity[_with_children](world, entity, ui);
}

jakobhellermann avatar Jan 05 '23 20:01 jakobhellermann