This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

How can I connect the signal joy_connection_changed in c#?

Is there a way to get the Input singleton reference so that I can connect the signal?

Thanks in advance!

Godot version 3.5
in Engine by (36 points)

1 Answer

0 votes
Best answer

Hi petr0m,

here you go:

public override void _Ready()
{
    Input.Singleton.Connect("joy_connection_changed", this, nameof(OnJoyConnectionChanged));
}

private void OnJoyConnectionChanged(int device, bool connected)
{

}

This will give you the Id of the Gamepad and tells you if its connected or removed.

But yes, this was not obvious. I had to read the docs too:
https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_differences.html?highlight=joy_connection_changed#singletons

https://docs.godotengine.org/en/stable/classes/class_input.html?highlight=joy_connection_changed#signals

by (1,081 points)
selected by

Awesome, thanks this worked!

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.