Search Unity

Resolved Linux build error: Namespace name 'DualShock4GamepadHID' does not exist

Discussion in 'Input System' started by tobias_froihofer, May 9, 2022.

  1. tobias_froihofer

    tobias_froihofer

    Joined:
    Jul 30, 2015
    Posts:
    56
    I have this code to identify the currently used device (gamepad).

    Code (CSharp):
    1. //...
    2.  
    3. InputDevice activeDevice = playerInput.devices[0];
    4.  
    5.             if (activeDevice is UnityEngine.InputSystem.XInput.XInputController)
    6.             {
    7.                 return Instance.xBoxIconSet;
    8.             }
    9.  
    10.             if (activeDevice is UnityEngine.InputSystem.DualShock.DualShock3GamepadHID)
    11.             {
    12.                 return Instance.ps3IconSet;
    13.             }
    14.  
    15.             if (activeDevice is UnityEngine.InputSystem.DualShock.DualShock4GamepadHID)
    16.             {
    17.                 return Instance.ps4IconSet;
    18.             }
    19.  
    20.             if (activeDevice is UnityEngine.InputSystem.DualShock.DualSenseGamepadHID)
    21.             {
    22.                 return Instance.ps5IconSet;
    23.             }
    24.  
    25.             if (activeDevice is UnityEngine.InputSystem.DualShock.DualShockGamepad)
    26.             {
    27.                 return Instance.ps4IconSet;
    28.             }
    29.  
    30.             if (activeDevice is UnityEngine.InputSystem.Switch.SwitchProControllerHID)
    31.             {
    32.                 return Instance.switchIconSet;
    33.             }
    34.  
    35. //....
    I can build and it works in Windows, but when I try to build for Linux I get some build time errors:

    error CS0234: The type or namespace name 'DualShock3GamepadHID' does not exist in the namespace 'UnityEngine.InputSystem.DualShock' (are you missing an assembly reference?)
    error CS0234: The type or namespace name 'DualShock4GamepadHID' does not exist in the namespace 'UnityEngine.InputSystem.DualShock' (are you missing an assembly reference?)
    error CS0234: The type or namespace name 'DualSenseGamepadHID' does not exist in the namespace 'UnityEngine.InputSystem.DualShock' (are you missing an assembly reference?)
    error CS0234: The type or namespace name 'Switch' does not exist in the namespace 'UnityEngine.InputSystem' (are you missing an assembly reference?)

    upload_2022-5-9_10-57-33.png

    It seems like this is a bug in the Input System package, or am I missing something?
    Tested and reproduced with Unity 2019.4.11f1, 2020.3.22, 2021.3.1f1 and Input System 1.2.0 and 1.3.0
     
  2. tobias_froihofer

    tobias_froihofer

    Joined:
    Jul 30, 2015
    Posts:
    56
    So I got some information from Unity about this stating:

    "After consulting with the developers, this actually is the intended behavior. The code you are using to detect the used controller does not work on Linux. On Linux, we use a library not written by us to support PS3, PS4, PS5, and Switch controllers. This makes it so the code you are using does not work specifically on Linux. Instead, you could try InputDevice.description.product, and other such fields instead."

    What I ended up doing is to use this code only in non-Linux builds and also checking against the device names like so:
    Code (CSharp):
    1.  
    2.     InputDevice activeDevice = playerInput.devices[0];
    3. #if !UNITY_STANDALONE_LINUX && !UNITY_WEBGL
    4.     if (activeDevice is UnityEngine.InputSystem.DualShock.DualShock3GamepadHID)
    5.     {
    6.         return Instance.ps3IconSet;
    7.     }
    8.  
    9.     if (activeDevice is UnityEngine.InputSystem.DualShock.DualShock4GamepadHID)
    10.     {
    11.         return Instance.ps4IconSet;
    12.     }
    13.  
    14.     if (activeDevice is UnityEngine.InputSystem.DualShock.DualSenseGamepadHID) //Input System 1.2.0 or higher required (package manager dropdown menu -> see other versions)
    15.     {
    16.         return Instance.ps5IconSet;
    17.     }
    18.  
    19.     if (activeDevice is UnityEngine.InputSystem.Switch.SwitchProControllerHID)
    20.     {
    21.         return Instance.switchIconSet;
    22.     }
    23. #endif
    24.  
    25.     if (activeDevice is UnityEngine.InputSystem.DualShock.DualShockGamepad)
    26.     {
    27.         return Instance.ps4IconSet;
    28.     }
    29.  
    30.     if (activeDevice.name.Contains("DualShock3"))
    31.         return Instance.ps3IconSet;
    32.  
    33.     if (activeDevice.name.Contains("DualShock4"))
    34.         return Instance.ps4IconSet;
    35.  
    36.     if (activeDevice.name.Contains("DualSense"))
    37.         return Instance.ps5IconSet;
    38.  
    39.     if (activeDevice.name.Contains("ProController"))
    40.         return Instance.switchIconSet;
    41.  
     
    Last edited: Dec 8, 2022
    datablob and JonathanTheDev like this.
  3. datablob

    datablob

    Joined:
    Dec 19, 2020
    Posts:
    9
    mind adding this to the documentation?
    @Schubkraft