From 7fc8318b7f3866011e1e887b4f5870ff7bb67c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Maita?= <47983254+mnmaita@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:05:11 +0100 Subject: [PATCH] BRP System Ordering (#16198) # Objective - Attempts to fix #16042 ## Solution - Added a new `RemoteSystem` `SystemSet` for the BRP systems. - Changed the schedule on which these systems run from `Update` to `Last`. ## Testing - I did not test these changes and would appreciate a hand in doing so. I assume it would be good to test that you can order against these systems easily now. --- ## Migration Guide - `process_remote_requests`, `process_ongoing_watching_requests` and `remove_closed_watching_requests` now run in the `Last` schedule. Make sure you use `RemoteSystem` `SystemSet` in case you need to order your systems against them. --- crates/bevy_remote/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/bevy_remote/src/lib.rs b/crates/bevy_remote/src/lib.rs index 00e8cf1550..9dab9fc4f1 100644 --- a/crates/bevy_remote/src/lib.rs +++ b/crates/bevy_remote/src/lib.rs @@ -301,11 +301,11 @@ //! [fully-qualified type name]: bevy_reflect::TypePath::type_path use async_channel::{Receiver, Sender}; -use bevy_app::prelude::*; +use bevy_app::{prelude::*, MainScheduleOrder}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ entity::Entity, - schedule::IntoSystemConfigs, + schedule::{IntoSystemConfigs, ScheduleLabel}, system::{Commands, In, IntoSystem, ResMut, Resource, System, SystemId}, world::World, }; @@ -434,11 +434,16 @@ impl Plugin for RemotePlugin { ); } + app.init_schedule(RemoteLast) + .world_mut() + .resource_mut::() + .insert_after(Last, RemoteLast); + app.insert_resource(remote_methods) .init_resource::() .add_systems(PreStartup, setup_mailbox_channel) .add_systems( - Update, + RemoteLast, ( process_remote_requests, process_ongoing_watching_requests, @@ -449,6 +454,10 @@ impl Plugin for RemotePlugin { } } +/// Schedule that contains all systems to process Bevy Remote Protocol requests +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +struct RemoteLast; + /// A type to hold the allowed types of systems to be used as method handlers. #[derive(Debug)] pub enum RemoteMethodHandler {