-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Entry-style APIs for Query #23052
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-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 accomplishedX-ContentiousThere are nontrivial implications that should be thought throughThere are nontrivial implications that should be thought through
Description
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-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 accomplishedX-ContentiousThere are nontrivial implications that should be thought throughThere are nontrivial implications that should be thought through
Type
Fields
No fields configured for issues without a type.
Projects
StatusShow more project fields
SME Triaged
What problem does this solve or what need does it fill?
It is common to need to write code which operates on a component, or adds it if it exists.
Because of this, we have a wonderful (and under-appreciated) method: [
EntityWorldMut::entry]. This mirrors the standard Rust convention: similarly methods exist onHashMapfor example.What solution would you like?
Entry<C: Component>QueryDatatypeThis type would return an
Entry-style wrapper over aMut<C>. This could be converted to aMut<C>(or a eldritch equivalent) using methods like.or_default(), allowing you to operate on the data as if it was always there.In order for this to work smoothly, we need to somehow actually send the command to spawn / insert the data you just mutated after the system concludes. I think a
Dropimpl might be able to do the trick, although a persistent mutable reference to the command data inside ofEntityCommandsstored inside of the containedQuerymight work too, albeit with some level of pain due to the borrow checker.What alternative(s) have you considered?
Leave it alone: you can just write branching code and take both
QueryandCommands.Additional context
This was originally proposed by @ecoskey on Discord.