Skip to content

Conversation

Nintorch
Copy link
Contributor

@Nintorch Nintorch commented Aug 18, 2025

Fixes #109717

Make sure that SDL events are processed when the SDL joypad input driver is initialized, this will allow it to register the connected controllers when the game starts. The registered controllers will then show up in Input.get_connected_joypads().

Before this PR image
After this PR image

I tested this PR on Windows and I thought this would fix it on all platforms 😅
TODO:

  • Fix this PR on macOS (the issue is also reproducible in Godot 4.4.1, so not technically a bug in this PR, I've read somewhere that it's a quirk of Apple's API)
  • Check if it fixes the issue on Linux

Make sure that SDL events are processed when the SDL joypad input driver is initialized, this will allow it to register the connected controllers when a game starts.
@Repiteo Repiteo added this to the 4.5 milestone Aug 18, 2025
@Repiteo Repiteo requested a review from a team August 18, 2025 19:02
@bruvzg bruvzg self-requested a review August 18, 2025 19:05
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it on macOS, I can reproduce the issue, but this change doesn't fix it.

@Nintorch
Copy link
Contributor Author

Thank you for testing, bruvzg! I will try to reproduce the issue tomorrow on macOS myself and I will try to fix it!

@bruvzg
Copy link
Member

bruvzg commented Aug 18, 2025

Most likely, it needs a system event pump (DisplayServer::process_events) to run to work.

@spookto
Copy link

spookto commented Aug 18, 2025

Tested on Linux (CachyOS) and it fixes the bug.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

@Nintorch
Copy link
Contributor Author

Thank you for testing, spookto and Calinou!

@Nintorch
Copy link
Contributor Author

@naturally-intelligent Sorry for bothering you, may I ask if this change fixes your issue?

@bruvzg
Copy link
Member

bruvzg commented Aug 19, 2025

Seems like in case of macOS it is detected after 5-10 main event loop iterations, so not sure if it's even fixable (or should be considered a bug at all).

@Nintorch
Copy link
Contributor Author

May I ask if the issue is also reproducible in Godot 4.4 on macOS?

@bruvzg
Copy link
Member

bruvzg commented Aug 19, 2025

Yes, it is the same 4.4.1.

@Nintorch
Copy link
Contributor Author

I see, thank you for testing!

@Nintorch Nintorch changed the title Handle SDL joypad events for connected controllers on game startup Handle SDL joypad events for connected controllers on game startup (on Windows and Linux) Aug 19, 2025
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in on Linux and Windows, in both cases issue is reproducible and fixed.

@Repiteo Repiteo merged commit c8b89b8 into godotengine:master Aug 19, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Aug 19, 2025

Thanks!

@Nintorch
Copy link
Contributor Author

Thank you! :D

@Nintorch Nintorch deleted the fix-get-connected-joypads branch August 19, 2025 15:33
@harrisyu
Copy link
Contributor

With this merge,, my gampad is not working, and with following message:

E 0:00:00:435   JoypadSDL::process_events: Error opening gamepad at index 1: IDirectInputDevice8::SetCooperativeLevel() DirectX error 0x80070006
  <C++ Error>   Condition "!gamepad" is true. Continuing.
  <C++ Source>  drivers\sdl\joypad_sdl.cpp:141 @ JoypadSDL::process_events()

Gamepad works again after revert it.
BTW, my OS = Windows 11, controller = 8 Bitdo - Ultimate C Wired Controller.

@Nintorch
Copy link
Contributor Author

Oops, I forgot about DInput controllers 😅 I will try to fix the problem

@Nintorch Nintorch restored the fix-get-connected-joypads branch August 21, 2025 08:04
@naturally-intelligent
Copy link

Fix works for me (as of beta7)
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input.get_connected_joypads() is returning empty array in 4.5
7 participants