bevy
bevy copied to clipboard
Having an `EntityMeta` SystemParam which gives access to an Entity's metadata
What problem does this solve or what need does it fill?
I was in a situation where I need to have:
- access to an entity's
EntityRef
to get some information about its archetype - mutable access to an entity's component (because the component stores a value that depends on the entity's archetype)
The problem is that EntityRef
conflicts with any mutable access of any component (I think) because it has methods get<C>
that lets you access the component value.
What solution would you like?
We could have a new SystemParam EntityMeta
that provides metadata information about an entity and its archetype without conflicting with any mutable access of other components, since EntityMeta
just returns metadata information.
&Entities
is already a valid SystemParam
which you can use to .get(entity)
the entity's metadata, including its ArchetypeId
. Given an ArchetypeId
you can get the archetype's data using an &Archetypes
, which is also a SystemParam
.
Maybe we could do an EntityMeta
implement WorldQuery
?
For this use case, why did EntityMut
not work? It should have all the methods that EntityRef
has and you can get mutable references to components.
Ah I didn't know about EntityMut
; I was able to make it work with EntityMut
!
I think it would be nice to improve the documentation on:
- which SystemParams are available. For example I was going on docs to find the list of system-params, but for some reason
Archetypes
is not listed there - which SystemParams conflict with which system-params?
I tried using
EntityMut
and anotherResource
but I was getting a conflict even though that otherResource
is not a component so could not possibly have any conflicting access with theEntityMut
. That might be a bug?
I can close this PR and open a new one for that specific bug
I see Archetypes
there.
There is a list on the system mod page https://docs.rs/bevy/latest/bevy/ecs/system/index.html. But it's hand maintained and easy to get out of date. So PRs are welcome there.
That might be a bug?
There's an issue for that already. https://github.com/bevyengine/bevy/issues/7255
I wouldn't mind leaving this open as I could see just getting EntityMeta
in a query useful.
#12398 should implement WorldQuery
and QueryData
for EntityLocation
, which is just missing the generation from the entity, which should be accessible already.