Skip to content

Commit

Permalink
despawn_descendants when DespawnMarker detected
Browse files Browse the repository at this point in the history
  • Loading branch information
RJ committed Sep 11, 2023
1 parent d91c898 commit 1f0181c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ pub mod prelude {
pub use crate::TimewarpSet;
}

use bevy::{
ecs::schedule::{BoxedSystemSet, ScheduleLabel},
prelude::*,
};
use bevy::prelude::*;
use prelude::*;

/// bevy_timewarp's systems run in these three sets, which get configured to run
Expand Down
8 changes: 4 additions & 4 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,18 +540,18 @@ pub(crate) fn check_for_rollback_completion(
/// despawn marker means remove all useful components, pending actual despawn after
/// ROLLBACK_WINDOW frames have elapsed.
pub(crate) fn remove_components_from_despawning_entities<T: TimewarpComponent>(
mut q: Query<(Entity, &mut ComponentHistory<T>), (Added<DespawnMarker>, With<T>)>,
mut q: Query<Entity, (Added<DespawnMarker>, With<T>)>,
mut commands: Commands,
game_clock: Res<GameClock>,
) {
for (entity, mut ct) in q.iter_mut() {
for entity in q.iter_mut() {
debug!(
"doing despawn marker component removal for {entity:?} / {:?}",
std::any::type_name::<T>()
);
// record_component_death looks at RemovedComponents and will catch this, and
// register the death (ie, comphist.report_death_at_frame)
commands.entity(entity).remove::<T>();
commands.entity(entity).remove::<T>().despawn_descendants();
// (also despawn any children, which in my game means the mesh/visual bits)
}
}

Expand Down

0 comments on commit 1f0181c

Please sign in to comment.