Skip to content

Components with required disabling components are hard to query #21363

@chescock

Description

@chescock

What problem does this solve or what need does it fill?

Internal components like Observer require an Internal component with a default query filter. Default query filters can be ignored by mentioning the type in the query, like With<Internal> or Allows<Internal>. But when the filter is added by a required component, the user may not know to mention it!

let mut world = World::new();
let entity = world.spawn(Observer::new(|_: On<Insert>| {})).id();

// This seems like it should work, but does not
let mut query = world.query::<&Observer>();
assert!(query.query(&world).get(entity).is_err());

// This is the workaround, but is hard to discover
let mut query = world.query_filtered::<&Observer, Allow<Internal>>();
assert!(query.query(&world).get(entity).is_ok());

What solution would you like?

When a query mentions a component that requires a component with a default query filter, that filter should be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions