New Input System : device is not paired anymore when switching control scheme

Hi everyone,

I recently started using the New Input System and so far I think I understood the basics of Player Input, Action Map, Action Schemes etc.

I’m creating a game where the player can either play using the Keyboard or a Gamepad, and I want the game to switch to the current one based on player input. I used a Control Scheme for each device because it would be useful later on to know what the player is using for tutorials for example.

This is the code I used for switching between schemes :

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;

public sealed class InputManager : Singleton<InputManager>
    {
        [SerializeField] private PlayerInput playerInput;

        private void OnEnable()
        {
            InputSystem.onActionChange += OnActionChange;
        }

        private void OnDisable()
        {
            InputSystem.onActionChange -= OnActionChange;
        }


        private void OnActionChange(object obj, InputActionChange change)
        {
            Debug.Log($"On Action Change : {change}");
           
            if (obj is not InputAction action) return;
            if (change != InputActionChange.ActionPerformed) return;

            var control = action.activeControl;

            if (control == null) return;

            playerInput.SwitchCurrentControlScheme(control.device);
    
        }
}

However in game when I start to use the Keyboard, the Gamepad is not detected anymore. I don’t know much about how to read the input debugger but it seems that once switching the device is not paired to the user anymore and therefore its input aren’t registered.

Note that I have no PlayerInputManager component in my scene and that the Gamepad is correctly detected and can be used as long as I don’t switch the control scheme.

Any idea on why this occurs and how to solve it ?
I’m also open to suggestions if you have any other way to manage multiple devices !

Hello!

Did you find a solution?

Sadly I did not.

Furthermore since then I have moved on to another project so I haven’t really touched on the subject for months haha.