+1 vote

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?

asked Sep 6, 2017 in Engine by Chain (69 points)

1 Answer

+2 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")
answered Sep 6, 2017 by quijipixel (675 points)
selected Sep 6, 2017 by Chain
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 How to use this Q&A? before posting your first questions.