bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Having an `EntityMeta` SystemParam which gives access to an Entity's metadata

Open cBournhonesque opened this issue 1 year ago • 5 comments

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.

cBournhonesque avatar Jan 17 '24 15:01 cBournhonesque

&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.

SkiFire13 avatar Jan 17 '24 15:01 SkiFire13

Maybe we could do an EntityMeta implement WorldQuery?

alice-i-cecile avatar Jan 17 '24 15:01 alice-i-cecile

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.

hymm avatar Jan 17 '24 16:01 hymm

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 another Resource but I was getting a conflict even though that other Resource is not a component so could not possibly have any conflicting access with the EntityMut. That might be a bug?

I can close this PR and open a new one for that specific bug

cBournhonesque avatar Jan 17 '24 17:01 cBournhonesque

I see Archetypes there.

image

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.

hymm avatar Jan 17 '24 18:01 hymm

#12398 should implement WorldQuery and QueryData for EntityLocation, which is just missing the generation from the entity, which should be accessible already.

james7132 avatar Mar 10 '24 12:03 james7132