+4 votes

Hello!

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 (73 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:
        print(Input.get_joy_name(device_id))
    else:
        print("Keyboard")
by (697 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?

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.