#Adding Dynamic Components
1 messages · Page 1 of 1 (latest)
Stores and exposes operations on entities, components, resources, and their associated metadata.
insert with reflection?
mm using ReflectComponent...
This could work
well that's gonna go through ReflectComponentFn which will leave me with a world, entity, and dynamic reflected component
Oh I guess I'm supposed to cast via function pointer or something
@dense gate is there anyway to do something like insert_by_id with a pointer to data or something?
nvrmnd TypeRegistration may work
ehhh actually that won't work either...
Deferring to @random forge and @silver cargo here 🙂
For when y'all arrive, I'm trying to do some cursed stuff:
I want to dynamically add components to entities in order to get entities into different archetypes
so I could have two (Position, Health, Chunk) entities exist as two separate archetypes with Chunk being a dynamically inserted ComponentId
why do you want to separate them across archetypes?
Just experimenting
I want to see if I can move dynamically move entities closer together in memory essentially
moving things across archetypes like that just moves them apart in memory
yes
if you want them close then you have to keep them in the same archetype
uhh so lets say I have 400 entities of the same archetype
and I want entities 1 and 400 closer together
based on some dynamic property
the exact thing I'm trying to do is see if I can create tilemap chunks like this
so pretty much every tile is the same archetype, but I want to essentially have sub archetypes based on the chunk the tile is in, which is not type level information
so like... you're trying to strategically add and remove tiles from the archetype to sort them how you want?
yeah
do you need to use dynamic components then? Can't you just make a Mover ZST that you use to remove, and then remove it to put them back in?
No since it's going to be an undefined number of chunks
so for instance, every 64 by 64 tile entities, I would want to group in their own set of archetypes
exactly
that makes more sense
I basically want something like (Chunk<1, 2, 3>, TilePos) as an entity, but not using const generics because then I can't really do it
tbh I don't know anything about dynamic components and am too sick to think about it very hard rn but dubi steinkek might be more familiar.
kind of a weird use case but I think it could lead to some cache improvements in tilemap libs
Damn, I hope you get better
I just got over covid and yeesh that was not a fun two weeks
thankfully doesn't feel like covid but still don't feel great
also not too bad either way just kinda gross
if this isn't something possible yet it would be a fun capability to try and add myself
Yes, you could probably do this with dynamic components + trait queries, once we have full dynamic query support
Sick, any work items or RFCs to look at on this? I've been needing an outside of work project
https://github.com/bevyengine/bevy/pull/6390 This needs reviews
And then @exotic moth will likely need help getting the trait query crate to play nice
Components-as-entities would also super charge trait queries, but I'm unsure if it's needed
Components as entities?
As in you can use your own component as an indexer instead of entity?
No, as in "instead of a type registry, registry the component types and their metadata in the ECS" in an isolated partition
Which should let us have e.g. ?Sized trait queries
At least, that's my intuition. Need to do more experiments to be sure
what do you mean by ?Sized trait queries?
For non object safe traits
May need to tweak the syntax but that's worth it
(a bit feverish so this is a little speculative)
oh, wild
If all you need to do is insert a dynamic component with a known layout you don't need reflection, just something like https://github.com/bevyengine/bevy/pull/5602