The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+4 votes


I have a small tutorial in my game, which should tell the player how controlls work. There are not many, but it doesn't hurt to show them anyway.

So my game supports controller and keyboard + mouse. If the player has a controller plugged in, I want to show him the controller controls and if not, I want to show him the keyboard + mouse controls.

Now I have something like this already implemented which checks the MOUSE MODE. It works fine, but can only detect the controller if a button or a joystick was moved or pressed.

Is there anyway to check if a controller is connected?

in Engine by (70 points)

1 Answer

+8 votes
Best answer

Use the signal joy_connection_changed from the Input object:

func _ready():
    Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")

Then on the _on_joy_connection_changed method you can check wether it's connected or not:

func _on_joy_connection_changed(device_id, connected):
    if connected:
by (699 points)
selected by

Thanks a lot. I wanted this for my shooter game that will have controller support

Hello! This works but if controller is plugged before opening the game it thinks that user is using keyboard. How can I check if controller is connected while entering the game for the first time?

to bUguette

There is a function just for that: Input.get_connected_joypads()
If there are no controllers connected the return value's gonna be an empty Array. If only one controller is connected it's [0]. Godot docs link is here.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.