-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add EntityMut::components and EntityRef and EntityWorldMut equivalent #13127
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
What problem does this solve or what need does it fill?
Some users (and applications) prefer a more game-object style of writing Bevy: fetching fat components directly from the ECS and quickly changing the data needed as their systems evolve.
This style can be comfortable and productive to write, but this path isn't adequately taught or supported.
In particular, accessing multiple components from a single entity in an ad hoc way is very useful for avatar-centric games like platformers or ARPGs, but is frustrating to do.
What solution would you like?
This proposed method takes any type that implements
QueryData(like(&mut Transform, &Life)and returns the type that would be fetched by an equivalent query. Note that the type signature is actually messier, using as associated types and anas WorldQuery.Both
EntityMutandEntityWorldMutshould have this method added as is.EntityRefrequires an additional bound onD: it must instead be aReadOnlyQueryData.What alternative(s) have you considered?
There's various
getmethods which return a single component at a time. These are less flexible, as they return only a single component.We could return a
Resultwith aQueryItemError, likeQuery::get, but most of its variants will never be hit.We could add a
QueryFiltergeneric to these methods, but there's no point: we're already working on a single entity!We could add a
get_components_mutmethod, and haveget_componentsas a way to fetch the read-only form. Given that this is a convenience API designed for handcrafted code, I don't think this is a useful transformation to expose here at the cost of ergonomics.We could make this panicking by default or add a panicking equivalent, but as per #12660, this is likely to increase user suffering overall.
Additional context