Skip to content

Commit

Permalink
Add RemovedComponentEvents::iter (bevyengine#12815)
Browse files Browse the repository at this point in the history
# Objective

Sometimes it's useful to iterate over removed entities. For example, in
my library
[bevy_replicon](https://github.com/projectharmonia/bevy_replicon) I need
it to iterate over all removals to replicate them over the network.

Right now we do lookups, but it would be more convenient and faster to
just iterate over all removals.

## Solution

Add `RemovedComponentEvents::iter`.

---

## Changelog

### Added

- `RemovedComponentEvents::iter` to iterate over all removed components.

---------

Co-authored-by: Pablo Reinhardt <126117294+pablo-lua@users.noreply.github.com>
  • Loading branch information
2 people authored and chompaa committed Apr 5, 2024
1 parent 53d4b37 commit c736e8d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/removal_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ impl RemovedComponentEvents {
}
}

/// Returns an iterator over components and their entity events.
pub fn iter(&self) -> impl Iterator<Item = (&ComponentId, &Events<RemovedComponentEntity>)> {
self.event_sets.iter()
}

/// Gets the event storage for a given component.
pub fn get(
&self,
Expand Down

0 comments on commit c736e8d

Please sign in to comment.