The usage of bevy-ecs makes me feel very comfortable. But when using Commands to modify the World, I did not find a method for removing only one components, so how should I remove only one component from the entity? Do I have to use the thread local system to get the world then remove it?
I think you want Commands::remove_one<Component>?
https://github.com/bevyengine/bevy/blob/979a1346a16898335bf1fe130c81d20297cd45e0/crates/bevy_ecs/src/system/commands.rs#L347-L355
I wrote that function and that is the correct use case. :+1:
commands.remove_one::<SomeComponent>(entity);
Ah, close enough. I still haven't internalised the turbofish rules
Note that Commands::remove_one is not on a released version of bevy yet.
Do I have to use the thread local system to get the world then remove it?
Using the current version on crates.io, 0.1.2, that seems to be the only way.
Alternatively, you may specify bevy as a git dependency until the next release, something like:
# Cargo.toml
[dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", rev = "979a134" }
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories
Note this should be avoided if possible, this is by design a pretty slow function: bevy tracks groups of entities that have the same components (such a group is called an archetype). When you remove a component, the entity will change archetype
Is there a god alternative to recommend? (For better performance) I am admittedly new to game design using ECS, but would plan on using components to add/remove statuses. E.g. add a poison component to deal damage over time and remove when healed or after some amount of time.
In cases like these (multiple seconds between adding/removing components for maybe a hundred entities), is the performance hit from changing archetypes a concern?
In cases like these (multiple seconds between adding/removing components for maybe a hundred entities), is the performance hit from changing archetypes a concern?
Probably not if it's at the scale of a second, if you're doing that a few thousands of times a frame it's going to start to take a toll
Is there a god alternative to recommend?
Another option would be to just add an Option<Poison> component from the beginning. For something like poison, it's probably fine to just use Poison component though
Yup OptionStatusEffect component, which then contains things like Poison inside.
Thank you everyone, I made a mistake. I forgot to check the master branch, so actually this should be what the next version will have.
Most helpful comment
Note this should be avoided if possible, this is by design a pretty slow function: bevy tracks groups of entities that have the same components (such a group is called an archetype). When you remove a component, the entity will change archetype