Query<Option<&Disabled>> falsely skips over entities with Disabled components.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
bevy 0.19.1
w/ default features
## What you did
I spawned an entity with the ``Disabled`` component.
```rust
fn setup(mut commands: Commands) {
commands.spawn(Disabled);
}
```
I tried querying all entities with or without a ``Disabled`` component.
```rust
fn test(query: Query>) {
for opt_disabled in query {
if opt_disabled.is_some() {
println!("found a disabled entity!");
}
}
}
```
## What went wrong
the query ``Query>`` 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](https://docs.rs/bevy_ecs/latest/bevy_ecs/entity_disabling/index.html) and the default query filter should therefore not apply here.
## Additional information
below is some code to quickly reproduce the issue:
```rust
use bevy::{
ecs::{entity_disabling::Disabled, resource::IsResource},
prelude::*,
};
fn setup(mut commands: Commands) {
commands.spawn(Disabled);
}
fn test1(query: Query, Without>) {
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, Option<&Disabled>), Without>) {
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>>``, which was how I stumbled upon this in the first place.
Including ``Has`` or ``Added``, ``Changed`` and ``Allow`` all make the ``Option<&Disabled>`` param work as expected.
Contributor guide
Research direction
Start with the entity_disabling documentation and the supplied setup, test1, and test2 reproduction entry points. Investigate how Query> applies the default disabled-entity filter, then add or adapt a regression test for the failing query. Done means the query finds the entity spawned with Disabled without requiring Has or another explicit filter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100