Proposal towards modern EntityNote
for better window ergonomics and more
#12521
Labels
A-ECS
Entities, components, systems, and events
C-Feature
A new feature, making something new possible
X-Controversial
There is active debate or serious implications around merging this PR
What problem does this solve or what need does it fill?
In bevy, there are a few places where indexing an entity is kinda hacked and feels unergonomic. This applies to
WindowRef
, where we either want to get the onePrimary
window, where there technically can still be 0 or more, or any other window entity referenced by itsEntityId
. This proposal wants to break the one hardcodedPrimary
special case, provide a more ergonomic way to get the actual entity behind a window and give the user the power to use markers other thanPrimary
for windows or other kinds of stuff.What solution would you like?
The general term would be entity labeling/marking.
Instead of a
WindowRef
, we should have an enum which can either directly access an entity via its id, or retrieve a singleton entity by a given marker. It would look something like this:(I was originally heading for
EntityRef
, but that's already used, better name proposals welcome :3)A
WindowRef
would then be handled like this:EntityNote
s should only be used for stuff where things don't break after changing the entity behind a marker.Markers are dynamic identifiers for entitys, every marker should directly refer to one entity. What happens when a marker is unset and if there should be an "optional" marker where we can also remove the marker is yet to answer.
There currently are two ideas towards handling entity markers:
Resource-based markers
See #6556
The idea is to have a resource which contains the actual
EntityId
and can be easily changed from any system by just mutating that resource. One big advantage about this is that it's fairly easy to implement and already has a (not-updated and horrible) prototype from me:bevy_ecs_markers
.Singleton Components
See #8944
The idea is to make a component which can only be applied once in the whole ecs world. While this has some caveats such as that we have to go deeply into the ecs and that it's also unsure how and if this will work for enum markers as seen in the example in #6556, one advantage I could think of is that when we want it, we could still use
With
andWithout
in queries to make non-overlapping systems run in parallel.I think we should investigate both and see what gives us better performance and ergonomics.
What alternative(s) have you considered?
Just use a boring util, e.g.
to have at least some better ergonomics hiding the two queries.
The text was updated successfully, but these errors were encountered: