#Querying Entities Without Multiple Components in Bevy ECS
13 messages · Page 1 of 1 (latest)
Query<
...,
(
With<CompNode>,
Without<Root>, // Need to exclude only entities with both Root and FrameCompNode
Without<Selected>,
Without<Locked>,
),
>
Logs
INFO: [log_entity_components] Entity (5v1) has the following components:
- dyn_comp_bundles::components::nodes::CompNode
- dyn_comp_bundles::components::nodes::FrameCompNode
- bevy_transform::components::transform::Transform
- bevy_transform::components::global_transform::GlobalTransform
- dyn_comp_bundles::components::mixins::SizeMixin
- dyn_comp_bundles::components::mixins::CornerRadiiMixin
- dyn_comp_bundles::components::mixins::VisibilityMixin
- dyn_comp_bundles::components::mixins::BlendModeMixin
- dyn_comp_bundles::components::mixins::OpacityMixin
- dyn_comp_bundles::components::mixins::StyleChildrenMixin
- bevy_hierarchy::components::parent::Parent
- bevy_hierarchy::components::children::Children
- dyn_comp_bundles::components::mixins::HierarchyLevel
- dyn_comp_bundles::components::mixins::PathMixin
- dyn_comp_svg_builder::svg::svg_bundle::SvgBundleVariant
index.js:428 INFO: [log_entity_components] Entity (7v1) has the following components:
- dyn_comp_bundles::components::nodes::CompNode
- bevy_transform::components::transform::Transform
- bevy_transform::components::global_transform::GlobalTransform
- dyn_comp_bundles::components::mixins::SizeMixin
- dyn_comp_bundles::components::mixins::CornerRadiiMixin
- dyn_comp_bundles::components::mixins::VisibilityMixin
- dyn_comp_bundles::components::mixins::BlendModeMixin
- dyn_comp_bundles::components::mixins::OpacityMixin
- dyn_comp_bundles::components::mixins::StyleChildrenMixin
- dyn_comp_bundles::components::nodes::RectangleCompNode
- bevy_hierarchy::components::parent::Parent
- dyn_comp_bundles::components::mixins::HierarchyLevel
- dyn_comp_bundles::components::mixins::PathMixin
- dyn_comp_svg_builder::svg::svg_bundle::SvgBundleVariant
Currently, adding Without<FrameCompNode> to the tuple (which should be AND?) excludes all entities with FrameCompNode, which isn't the intended behavior. How can I adjust this?
Query<
...,
(
With<CompNode>,
Without<Root>,
Without<FrameCompNode>, // Now no FrameCompNode is queried anymore no matter whether it has Root or no Root component
Without<Selected>,
Without<Locked>,
),
>
Logs
INFO: [log_entity_components] Entity (7v1) has the following components:
- dyn_comp_bundles::components::nodes::CompNode
- bevy_transform::components::transform::Transform
- bevy_transform::components::global_transform::GlobalTransform
- dyn_comp_bundles::components::mixins::SizeMixin
- dyn_comp_bundles::components::mixins::CornerRadiiMixin
- dyn_comp_bundles::components::mixins::VisibilityMixin
- dyn_comp_bundles::components::mixins::BlendModeMixin
- dyn_comp_bundles::components::mixins::OpacityMixin
- dyn_comp_bundles::components::mixins::StyleChildrenMixin
- dyn_comp_bundles::components::nodes::RectangleCompNode
- bevy_hierarchy::components::parent::Parent
- dyn_comp_bundles::components::mixins::HierarchyLevel
- dyn_comp_bundles::components::mixins::PathMixin
- dyn_comp_svg_builder::svg::svg_bundle::SvgBundleVariant
i actually think AND is what you need here.
Query<..., (Without<Root>, Without<FrameCompNode>)> means only entities where both filters apply are filtered out
AND in filters is a tuple of filters
Wouldn't it be something like Or<(With<Root>, Without<FrameCompNode>), (Without<Root>, With<FrameCompNode>)>?
i thought the goal was to exclude entities which have both but not those which only have one
I think the Or query should achieve that 🤔
an and should've solved it but it didn't work for me as you can see in my second example,
where the 5v1 entity isn't listed in the logs anymore although it is not Root Node
This should do the trick, either just one or just the other
Yeah it works.. Thanks for the hint 🙂
But an and in some way would be ofc more streamlined I guess
Or<(
(Without<Root>, With<FrameCompNode>),
(With<Root>, Without<FrameCompNode>),
(Without<Root>, Without<FrameCompNode>),
)>, // Exclude root frame nodes
If you're also excluding the "neither" case, you're much better off using Or<(Without<A>, Without<B>)>, does that work as well?