From 309745c7c6f9df6851bdba68e14ebd7d23a36e19 Mon Sep 17 00:00:00 2001 From: uwuPyxl Date: Mon, 11 Mar 2024 21:05:10 +0100 Subject: [PATCH] Send GamepadEvent for gamepads connected at startup (#12424) # Objective - Fix GamepadEvent::Connection not being sent for devices connected at startup. ## Solution - GamepadConnectionEvent was being sent directly for gamepads connected at startup, which causes consumers of GamepadEvent to not receive those events. - Instead send GamepadEvent. The gamepad_event_system splits GamepadEvent up, so consumers of GamepadConnectionEvent will still receive the events. --- crates/bevy_gilrs/src/gilrs_system.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/bevy_gilrs/src/gilrs_system.rs b/crates/bevy_gilrs/src/gilrs_system.rs index e0e111cb4d..331bccb0ca 100644 --- a/crates/bevy_gilrs/src/gilrs_system.rs +++ b/crates/bevy_gilrs/src/gilrs_system.rs @@ -18,17 +18,20 @@ use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter}; pub fn gilrs_event_startup_system( #[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut, #[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut, - mut connection_events: EventWriter, + mut events: EventWriter, ) { for (id, gamepad) in gilrs.0.get().gamepads() { let info = GamepadInfo { name: gamepad.name().into(), }; - connection_events.send(GamepadConnectionEvent { - gamepad: convert_gamepad_id(id), - connection: GamepadConnection::Connected(info), - }); + events.send( + GamepadConnectionEvent { + gamepad: convert_gamepad_id(id), + connection: GamepadConnection::Connected(info), + } + .into(), + ); } }