Skip to content

Commit cd36d3b

Browse files
committed
Replace RemovedComponents<T> backing with Events<Entity> (#5680)
# Objective Removal events are unwieldy and require some knowledge of when to put systems that need to catch events for them, it is very easy to end up missing one and end up with memory leak-ish issues where you don't clean up after yourself. ## Solution Consolidate removals with the benefits of `Events<...>` (such as double buffering and per system ticks for reading the events) and reduce the special casing of it, ideally I was hoping to move the removals to a `Resource` in the world, but that seems a bit more rough to implement/maintain because of double mutable borrowing issues. This doesn't go the full length of change detection esque removal detection a la bevyengine/rfcs#44. Just tries to make the current workflow a bit more user friendly so detecting removals isn't such a scheduling nightmare. --- ## Changelog - RemovedComponents<T> is now backed by an `Events<Entity>` for the benefits of double buffering. ## Migration Guide - Add a `mut` for `removed: RemovedComponents<T>` since we are now modifying an event reader internally. - Iterating over removed components now requires `&mut removed_components` or `removed_components.iter()` instead of `&removed_components`.
1 parent b4fb4d3 commit cd36d3b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/system.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use bevy_ecs::{
22
entity::Entity,
33
event::EventWriter,
44
prelude::{Changed, Component, Resource},
5-
system::{Commands, NonSendMut, Query, RemovedComponents},
5+
removal_detection::RemovedComponents,
6+
system::{Commands, NonSendMut, Query},
67
world::Mut,
78
};
89
use bevy_utils::{
@@ -89,7 +90,7 @@ pub(crate) fn create_window<'a>(
8990
pub struct WindowTitleCache(HashMap<Entity, String>);
9091

9192
pub(crate) fn despawn_window(
92-
closed: RemovedComponents<Window>,
93+
mut closed: RemovedComponents<Window>,
9394
window_entities: Query<&Window>,
9495
mut close_events: EventWriter<WindowClosed>,
9596
mut winit_windows: NonSendMut<WinitWindows>,

0 commit comments

Comments
 (0)