Query<Option<&Disabled>> falsely skips over entities with Disabled components.
Bevy version and features
bevy 0.19.1 w/ default features
What you did
I spawned an entity with the Disabled component.
fn setup(mut commands: Commands) {
commands.spawn(Disabled);
}
I tried querying all entities with or without a Disabled component.
fn test(query: Query<Option<&Disabled>>) {
for opt_disabled in query {
if opt_disabled.is_some() {
println!("found a disabled entity!");
}
}
}
What went wrong
the query Query<Option<Disabled>> never matched any disabled entities.
This should not be the case because the query explicitly mentions the Disabled component as described in the entity_disabling docs and the default query filter should therefore not apply here.
Additional information
below is some code to quickly reproduce the issue:
use bevy::{
ecs::{entity_disabling::Disabled, resource::IsResource},
prelude::*,
};
fn setup(mut commands: Commands) {
commands.spawn(Disabled);
}
fn test1(query: Query<Option<&Disabled>, Without<IsResource>>) {
for disabled_ref in query {
if disabled_ref.is_some() {
println!("test1 found an entity with a 'Disabled' component");
}
}
}
fn test2(query: Query<(Entity, Has<Disabled>, Option<&Disabled>), Without<IsResource>>) {
for (entity, has_disabled, disabled_ref) in query {
if has_disabled && disabled_ref.is_some() {
println!("test2 found entity {} with a 'Disabled' component", entity,);
}
}
}
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_systems(Startup, (setup, (test1, test2)).chain())
.run();
}
test2 successfully finds and prints the entity added in setup, but test1 never finds any entity and thus never prints to the console upon running the app.
This also fails for Query<Option<Ref<Disabled>>>, which was how I stumbled upon this in the first place.
Including Has<Disabled> or Added<Disabled>, Changed<Disabled> and Allow<Disabled> all make the Option<&Disabled> param work as expected.
Source: bevyengine/bevy