Skip to content

Lack of ability to inspect mutable queries via &self receiver in 0.6 breaks Rapier integration #2744

@pcwalton

Description

@pcwalton

Bevy version

0.6 prerelease, f6b42b8

Details

The Rapier physics library abstracts over scene graphs with traits called ComponentSet and ComponentSetMut, where ComponentSetMut requires that ComponentSet be implemented. ComponentSet allows immutable lookup of physics-related properties with a fn get(&self, ...) -> Option<&T>, while ComponentSetMut allows mutation of those properties with fn set(&mut self, ...). The bevy_rapier crate targeting Bevy 0.5 implements this trait on a QuerySet that performs immutable and mutable versions of the query, and takes advantage of the fact that fn q0(&self) and fn q0_mut(&mut self) are separate methods. But in Bevy 0.6 as of #2605, the fn q0(&self) method has been removed in favor of the mutable version. This means that it's not possible to safely simultaneously implement ComponentSet and ComponentSetMut anymore on a query.

The best safe workaround I can think of is to copy all the physics-related data for every entity out to a temporary collection every frame and then copy it back in after the physics code has run. This is obviously not shippable :) Even the Bevy 0.5 workaround isn't great, because it performs the query twice.

It'd be very nice if temporary immutable access to mutable queries were possible, by borrowing the mutable query. I'm not familiar enough with all the lifetimes involved to be able to propose a concrete API here, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-PhysicsCollisions, kinematics, forces and moreC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions