Add RenderStartup schedule to the RenderApp (#19841)

# Objective

- We sometimes want to spawn things on startup that only exist in the
RenderApp but right now there's no equivalent to the Startup schedule on
the RenderApp so we need to do all of that in the plugin build/finish
code

## Solution

- Add a RenderStartup schedule that runs on the RenderApp after the
plugins are initialized

## Testing

- I ported the custom_post_processing example to use this new schedule
and things worked as expected. I will push the change in a follow up PR
This commit is contained in:
IceSentry 2025-06-29 14:14:10 -04:00 committed by GitHub
parent 8d70649e7d
commit 37aae00120
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -217,10 +217,30 @@ pub enum RenderSystems {
PostCleanup,
}
/// The schedule that contains the app logic that is evaluated each tick
///
/// This is highly inspired by [`bevy_app::Main`]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct MainRender;
impl MainRender {
pub fn run(world: &mut World, mut run_at_least_once: Local<bool>) {
if !*run_at_least_once {
let _ = world.try_run_schedule(RenderStartup);
*run_at_least_once = true;
}
let _ = world.try_run_schedule(Render);
}
}
/// Deprecated alias for [`RenderSystems`].
#[deprecated(since = "0.17.0", note = "Renamed to `RenderSystems`.")]
pub type RenderSet = RenderSystems;
/// The startup schedule of the [`RenderApp`]
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]
pub struct RenderStartup;
/// The main render schedule.
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]
pub struct Render;
@ -531,7 +551,7 @@ unsafe fn initialize_render_app(app: &mut App) {
app.init_resource::<ScratchMainWorld>();
let mut render_app = SubApp::new();
render_app.update_schedule = Some(Render.intern());
render_app.update_schedule = Some(MainRender.intern());
let mut extract_schedule = Schedule::new(ExtractSchedule);
// We skip applying any commands during the ExtractSchedule
@ -546,6 +566,7 @@ unsafe fn initialize_render_app(app: &mut App) {
.add_schedule(extract_schedule)
.add_schedule(Render::base_schedule())
.init_resource::<render_graph::RenderGraph>()
.add_systems(MainRender, MainRender::run)
.insert_resource(app.world().resource::<AssetServer>().clone())
.add_systems(ExtractSchedule, PipelineCache::extract_shaders)
.add_systems(