Hello, I’m looking to implement Auto-Switch for my controls and I’m having some issues with devices fighting for control when I would expect my PlayerInput to maintain it’s current device until the other one provides input.
-I don’t have a physical Gamepad connected.
-I pair my PlayerInput with both InputSystem.GetDevice() and () on Start
-PlayerInput is set to send UnityEvents
On Screen controls with control path set to [Gamepad]
-These only call SendValueToControl while they are being interacted.
Keyboard controls
-WASD only seeing events in debug window while they are being pressed
The control scheme for the user will switch erratically to and from Gamepad when interacting with on screen controls but will switch back to keyboard without keyboard input.
Any tips would be appreciated. Thanks.
This morning I was able to reproduce the problem in the Warriors example project. I added a OnScreenControl slider with the control path set to Right Stick/X [Gamepad] and call SendValueToControl(slider.value) in the OnDrag method. The character rapidly switches between Keyboard and Gamepad control schemes and the slider does not move him.
I solved the problem by removing the default control schemes and using only one for Keyboard and one for Gamepad. I removed PlayerInput from my prefabs and set up the controls manually. The keyboard bindings have both schemes enabled to enable the on screen controls to send input as a Gamepad. Hope this helps someone.
var Controls = new SR_InputSettings
{
devices = new InputDevice[] { Gamepad.all[0], Keyboard.current },
bindingMask = InputBinding.MaskByGroup("Gamepad;Keyboard&Mouse")
};
InputUser HumanUser = InputUser.PerformPairingWithDevice(Gamepad.all[0]);
InputUser.PerformPairingWithDevice(Keyboard.current, HumanUser);
HumanUser.AssociateActionsWithUser(Controls);
HumanUser.ActivateControlScheme(Controls.KeyboardScheme);
Controls.Enable();
Controls.Vehicle.SetCallbacks(GetComponent<VehicleController>());