Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Input not working on build (custom HID)

Discussion in 'Input System' started by Osteel, Nov 12, 2019.

  1. Osteel

    Osteel

    Joined:
    Jan 17, 2014
    Posts:
    59
    Hey everyone,

    We've set up a custom HID layout (flightstick) and it works in the editor. However, there is no response when we test with a build, though other automatically generated input (keyboard/xbox controller) do work.

    The code is taken from the documentation and filled out to match the device information:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4. using UnityEngine.InputSystem.Layouts;
    5.  
    6. [InputControlLayout(stateType = typeof(ThrustmasterHIDInputReport))]
    7. #if UNITY_EDITOR
    8. [InitializeOnLoad]
    9. #endif
    10.  
    11. public class ThrustmasterJoystrickHID : Joystick
    12. {
    13.     static ThrustmasterJoystrickHID()
    14.     {
    15.         InputSystem.RegisterLayout<ThrustmasterJoystrickHID>(
    16.             matches: new InputDeviceMatcher()
    17.                 .WithInterface("HID")
    18.                 .WithCapability("vendorId", 1973)
    19.                 .WithCapability("productId", 790));
    20.     }
    21.  
    22.     [RuntimeInitializeOnLoadMethod]
    23.     static void Init() { }
    24. }
    Code (CSharp):
    1.  
    2. using System.Runtime.InteropServices;
    3. using UnityEngine.InputSystem.Layouts;
    4. using UnityEngine.InputSystem.LowLevel;
    5. using UnityEngine.InputSystem.Utilities;
    6.  
    7. [StructLayout(LayoutKind.Explicit, Size = 32)]
    8. struct ThrustmasterHIDInputReport : IInputStateTypeInfo
    9. {
    10.      public FourCC format => new FourCC('H', 'I', 'D');
    11.  
    12.     [FieldOffset(0)] public byte reportId;
    13.  
    14.     [InputControl(name = "stick", layout = "Stick", format = "VEC2")]
    15.     [InputControl(name = "stick/x", offset = 0, format = "BYTE",
    16.         parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,invert")]
    17.     [InputControl(name = "stick/y", offset = 1, format = "BYTE",
    18.         parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
    19.     [FieldOffset(1)] public byte stickX;
    20.     [FieldOffset(2)] public byte stickY;
    21.  
    22.     [InputControl(name = "trigger", layout = "Button", offset = 5, bit = 4)]
    23.     [FieldOffset(3)] public byte trigger;
    24. }
    25.  
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    What's the build target? There's a known bug in il2cpp which causes the static class constructor to not be invoked when Init() runs.
     
  3. Osteel

    Osteel

    Joined:
    Jan 17, 2014
    Posts:
    59
    Thanks Rene!

    So checking, and it was still set to default Mono. However, it made me think to try building it out on x86_64, and that seems to have worked.