Not sure if I'm understanding the purpose of the framework correctly, but, one of the reasons I was fairly interested in this library is that I am interested in having components that come and go declaratively. For example, imagine you have a Player entity which either has an Inventory component or not depending on some other state - and you can do this
fn compose(cx: ...) -> impl Compose {
if *some_state {
spawn((Player("Bob"), Inventory::default()))
} else {
spawn(Player("Bob"))
}
}
It seems that the spawn function only overwrites component state, but doesn't handle it when components are removed.
I'm not sure this is the right move, but one solution may be using .retain() on the entity with the type of the bundle provided:
pub fn spawn<'a, B>(bundle: B) -> Spawn<'a>
where
B: Bundle + Clone,
{
Spawn {
spawn_fn: Rc::new(move |world, cell| {
if let Some(entity) = cell {
world.entity_mut(*entity).retain::<B>(); // HERE
world.entity_mut(*entity).insert(bundle.clone());
} else {
*cell = Some(world.spawn(bundle.clone()).id())
}
}),
// ....
}
Although, to me this feels like it creates a potential problem. Lets say you have another bevy plugin which adds a "TargettedEnemy" entity to any "Player" entity - this change here would remove this any time it is called, making it impossible to "extend" that entity.
Not sure if I'm understanding the purpose of the framework correctly, but, one of the reasons I was fairly interested in this library is that I am interested in having components that come and go declaratively. For example, imagine you have a Player entity which either has an Inventory component or not depending on some other state - and you can do this
It seems that the
spawnfunction only overwrites component state, but doesn't handle it when components are removed.I'm not sure this is the right move, but one solution may be using
.retain()on the entity with the type of the bundle provided:Although, to me this feels like it creates a potential problem. Lets say you have another bevy plugin which adds a "TargettedEnemy" entity to any "Player" entity - this change here would remove this any time it is called, making it impossible to "extend" that entity.