Skip to content

Forces QueryData not able to call read-only functions from a ForcesReadOnlyItem #907

@Exotik850

Description

@Exotik850

When querying from a set of entities with the Forces QueryData, the user is unable to call any read-only functions defined on ForcesItem, e.g.

fn get_total_inertia(objects: Query<(Forces, &Mass)>) {
    let total = objects
        .iter()
        .map(|(forces, mass)| forces.linear_velocity() * mass.0)
        .reduce(|a, b| a + b);
}

returns the compilation error:

no method named linear_velocity found for struct forces::query_data::ForcesReadOnlyItem<'__w, '__s> in the current scope

A straightforward approach would be to implement each of the read-only functions from ForcesItem on ForcesReadOnlyItem here, that would return the same results as a ForcesItem. This would allow read-only access to Forces methods, freeing up time needed to mutably retrieve the components

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions