From a2fc9de16d839654b97a4d7de9f99481d7fccd72 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Thu, 15 Aug 2024 14:48:43 -0400 Subject: [PATCH] Add `RenderSet::FinalCleanup` for `World::clear_entities` (#14764) # Objective `World::clear_entities` is ambiguous with all of the other systems in `RenderSet::Cleanup` because it access `&mut World`. ## Solution I've added another system set variant, and made sure that this runs after everything else. ## Testing The `ambiguity_detection` example ## Migration Guide `World::clear_entities` is now part of `RenderSet::PostCleanup` rather than `RenderSet::Cleanup`. Your cleanup systems should likely stay in `RenderSet::Cleanup`. ## Additional context Spotted when working on #7386: this was responsible for a large number of ambiguities. This should be removed if / when #14449 is merged: there's no need to call `clear_entities` at all if the rendering world is retained! --- crates/bevy_render/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 8bd49ed2d1..32dff45d1d 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -104,7 +104,6 @@ pub struct RenderPlugin { /// The systems sets of the default [`App`] rendering schedule. /// -/// that runs immediately after the matching system set. /// These can be useful for ordering, but you almost never want to add your systems to these sets. #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] pub enum RenderSet { @@ -138,6 +137,10 @@ pub enum RenderSet { Render, /// Cleanup render resources here. Cleanup, + /// Final cleanup occurs: all entities will be despawned. + /// + /// Runs after [`Cleanup`](RenderSet::Cleanup). + PostCleanup, } /// The main render schedule. @@ -162,6 +165,7 @@ impl Render { Prepare, Render, Cleanup, + PostCleanup, ) .chain(), ); @@ -469,7 +473,7 @@ unsafe fn initialize_render_app(app: &mut App) { render_system, ) .in_set(RenderSet::Render), - World::clear_entities.in_set(RenderSet::Cleanup), + World::clear_entities.in_set(RenderSet::PostCleanup), ), );