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!
This commit is contained in:
Alice Cecile 2024-08-15 14:48:43 -04:00 committed by GitHub
parent ac29bdfc86
commit a2fc9de16d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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),
),
);