Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Problems with switching control scheme

Discussion in 'Input System' started by Jichaels, Oct 1, 2019.

  1. Jichaels


    Dec 27, 2018

    Currently working on a VR demo using the new input system, working great so far. Now I wanted to add a second control scheme to be able to play with mouse&keyboard aswell (and with gamepad later on), but I just CAN'T get it to work. :confused:

    I'm using PlayerInput with SendMessage (since Invoke Unity Events have been broken for a while).

    I'm facing two problem, if I toggle the Auto-Switch of the PlayerInput, my VR control scheme is getting set multiple times a frame, even if it's not moving, not on my head, and both controller are not moving aswell. Is this intended ? It makes the autoswitch useless :(

    So I tried to manually switch control scheme with a key, it KINDA works, as I'm able to switch control scheme, but there is no devices anymore in my PlayerInput so nothing works afterward.
    I tried both :
    - _playerInput.SwitchControlScheme("MyControlScheme");

    I also saw here that you can use InputActionReference to directly read into the action, instead of using PlayerInput. Should I look further into that, or stick with what I'm currently doing ? I'm so loooost :(
  2. Jichaels


    Dec 27, 2018
    I swear I'm trying everything, I'm going crazy

    If I have only ONE control scheme for VR, it works as expected. As soon as I add another control scheme, any tracked device don't work anymore, EVEN if VR is set as my default control scheme in PlayerInput, it's the other one getting used ?!

    I even tried gathering all devices and passing them when changing control scheme, and even if every single tracked device is there (under player input debug), I don't get anything.

    Another weird behaviour :

    this is my script for gathering devices :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    6. public class JVRDevices : MonoBehaviour
    7. {
    8.     public static JVRDevices Instance { get; private set; }
    10.     public InputDevice[] DevicesVR => _devicesVR.ToArray();
    11.     public InputDevice[] DevicesMouseKeyboard => _devicesMouseKeyboard.ToArray();
    13.     private List<InputDevice> _devicesVR = new List<InputDevice>();
    14.     private List<InputDevice> _devicesMouseKeyboard = new List<InputDevice>();
    16.     public bool debug;
    18.     private IEnumerator Start()
    19.     {
    20.         Instance = this;
    22.         yield return new WaitForSeconds(5);
    23.         foreach (var device in InputSystem.devices)
    24.         {
    25.             print(device.layout);
    26.             if (device.layout.Contains("Mouse") || device.layout.Contains("Keyboard"))
    27.             {
    28.                 _devicesMouseKeyboard.Add(device);
    29.             }
    30.             else if (device.layout.Contains("XR"))
    31.             {
    32.                 _devicesVR.Add(device);
    33.             }
    34.         }
    35.     }
    37.     private void Update()
    38.     {
    39.         if (debug)
    40.         {
    41.             debug = false;
    42.             print("---------------------------------------- VR devices ----------------------------------------");
    43.             foreach (var VARIABLE in _devicesVR)
    44.             {
    45.                 print(VARIABLE);
    46.             }
    48.             print("---------------------------------------- MouseKeyboard devices ----------------------------------------");
    49.             foreach (var VARIABLE in _devicesMouseKeyboard)
    50.             {
    51.                 print(VARIABLE);
    52.             }
    53.         }
    54.     }
    55. }
    if I don't yield some seconds in start, VR devices are not there (Headset is, but not the controllers nor the "trackingReferences").

    If anyone have any idea about what's going on, please share. Hopefully someone from unity can help me, it's driving me nuts T_T
  3. dgiddy


    May 6, 2020
    Hey I know this is old, but did you ever get a fix for this? We're having the same issue with control schemes, input works completely fine but as soon as another control scheme is added it just stops detecting anything.