From f793ce626e294ea43338034e07fd284cb5d5534d Mon Sep 17 00:00:00 2001 From: Lucas Poffo Date: Sat, 9 Nov 2024 14:16:32 -0300 Subject: [PATCH] BevyRenet: fix disconnect_on_exit not being called Call disconnect_on_exit on "Last" schedule, this mean it will handle the cases of exit_on_primary_closed/exit_on_all_closed or user submit AppExit events --- bevy_renet/src/netcode.rs | 20 ++++++++++++++++++-- bevy_renet/src/steam.rs | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/bevy_renet/src/netcode.rs b/bevy_renet/src/netcode.rs index a486d3bc..b74f56bd 100644 --- a/bevy_renet/src/netcode.rs +++ b/bevy_renet/src/netcode.rs @@ -27,7 +27,15 @@ impl Plugin for NetcodeServerPlugin { app.add_systems( PostUpdate, - (Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit) + Self::send_packets + .in_set(RenetSend) + .run_if(resource_exists::) + .run_if(resource_exists::), + ); + + app.add_systems( + Last, + Self::disconnect_on_exit .run_if(resource_exists::) .run_if(resource_exists::), ); @@ -71,7 +79,15 @@ impl Plugin for NetcodeClientPlugin { ); app.add_systems( PostUpdate, - (Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit) + Self::send_packets + .in_set(RenetSend) + .run_if(resource_exists::) + .run_if(resource_exists::), + ); + + app.add_systems( + Last, + Self::disconnect_on_exit .run_if(resource_exists::) .run_if(resource_exists::), ); diff --git a/bevy_renet/src/steam.rs b/bevy_renet/src/steam.rs index 0bcdc804..10a635aa 100644 --- a/bevy_renet/src/steam.rs +++ b/bevy_renet/src/steam.rs @@ -33,8 +33,10 @@ impl Plugin for SteamServerPlugin { app.add_systems( PostUpdate, - (Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit).run_if(resource_exists::), + Self::send_packets.in_set(RenetSend).run_if(resource_exists::), ); + + app.add_systems(Last, Self::disconnect_on_exit.run_if(resource_exists::)); } } @@ -78,7 +80,15 @@ impl Plugin for SteamClientPlugin { ); app.add_systems( PostUpdate, - (Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit) + Self::send_packets + .in_set(RenetSend) + .run_if(resource_exists::) + .run_if(resource_exists::), + ); + + app.add_systems( + Last, + Self::disconnect_on_exit .run_if(resource_exists::) .run_if(resource_exists::), );