Tainted \\ Coders

Query for removed components

Last updated:

Use RemovedComponents type to iterate over all removed entities

fn react_on_removal(
    mut removed: RemovedComponents<Dying>,
    mut query: Query<&mut Sprite>
) {
    // RemovedComponents returns us the entities
    for entity in &mut removed {
        // Which we use to query for other components on the entity
        if let Ok(mut sprite) = query.get_mut(entity) {
            // And remove red from any sprite components that are
            // not dying

RemovedComponents<T>::iter() returns an iterator with the Entitys that had their Component T (in this case Dying) removed at some point earlier during the tick.