Skip to content

Component Bundle Queries #2252

Closed
Closed
@aevyrie

Description

@aevyrie

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

Reduce the verbosity of queries by using bundles, which are already used for this purpose during entity archetype construction.

What solution would you like?

The ability to add a struct that derives Bundle to a query, and have it return with its fields accessible as components. E.g.:

#[derive(Bundle)]
struct Transform {
    translation: Translation,
    rotation: Rotation,
    scale: Scale,
}

// can still use this common case
Query<&Transform>

// but also, able to query fields granularly with change detection
Query<&Transform, Changed<Rotation>>
//...

// Can use this to group other sets of components as query-able bundles
#[derive(Bundle)]
struct Dog {
    legs: Legs
    fluffy_tail: Tail
    wet_nose: Nose
}
// These two queries are functionally equivalent, but the `Dog` query returns a list of `Dog` structs
Query<&Dog>
Query<(&Legs, &Tail, &Nose)>

What alternative(s) have you considered?

Most of this can already be achieved with some verbosity, as shown in the dog example above. However, it would also allow us to split apart common components like Transform into their parts with field level change detection, without losing the ergonomics of the Transform type.

Additional context

Similar to #786

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-PerformanceA change motivated by improving speed, memory usage or compile timesC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions