Controller Connected Bug

jaunger1999

New member
Hi,


I was trying to use the ControllerConnected state and found some issues with it.
The line 339 in PlayerInput.cs
var controllerConnected = Input.GetJoystickNames().Length > 0;
always returns true for me.
There is always one entry in the array that's a blank string if I don't have a controller connected.
I changed this line to
var joystickNames = Input.GetJoystickNames();
var controllerConencted = joystickNames.Length > 1 || (joystickNames.Length == 1 && joystickNames[0] != "");
Another issue I found is that the state is only active if I connect the controller after starting Play Mode.
I did not find a fix for this.


I'm using Unity 2020.322f1 Personal

Thanks.
 
Last edited:
I recommend using the new input system for better controller support. It's cases like these that the old input manager does not handle well
 
Ok so this is very funny to me.

I got the new input system working and now it seems like the ControllerConnected state doesn't get checked for at all.

If I'm understanding the code right, the ControllerConnected state is only set at line 339 in PlayerInput.cs. But before it does that, it checks if the bool CanCheckForController is true and returns if not. In UnityInputSystem.cs, this is overridden to false, so the function always returns. Which I kind of understand, seeing that Input.GetJoystickNames() checks with the old input manager I'm trying to avoid.

Am I understanding this right?
 
What I was getting at is that the ControllerConnected state is never activated.
I changed the source code myself to make it work but figured it was worth mentioning.
 
Top