From 66f7ee8a82bd574276a1784125ce6f6ec0934da6 Mon Sep 17 00:00:00 2001 From: myss Date: Thu, 25 Sep 2025 18:31:22 +0300 Subject: [PATCH] fix(HID): Use correct data format for composite stick axes in layout builder The generic HID layout builder made a faulty assumption that the X and Y axes of a composite "Stick" control always used a simple bitfield format (`SBIT`/`BIT`). This assumption is incorrect for many modern devices, most notably 6DoF controllers like the 3Dconnexion SpaceMouse, which report their axes as 16-bit shorts (`SHRT`). This bug caused the builder to apply the wrong data format, resulting in incorrect parsing and unusable stick input for these devices. This commit resolves the issue by replacing the brittle, hardcoded format logic with a call to the `element.DetermineFormat()` helper method. This is the same robust method used by the general-purpose element processor later in the same function. This change: - Fixes axis detection for 6DoF controllers and other HID devices that use `SHRT` or `BYTE` formats. - Makes the special-case "Stick" logic consistent with the rest of the HID parser. --- Packages/com.unity.inputsystem/InputSystem/Plugins/HID/HID.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/HID/HID.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/HID/HID.cs index 3e7354584b..0a304dc068 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/HID/HID.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/HID/HID.cs @@ -385,7 +385,7 @@ public InputControlLayout Build() var yElementParameters = yElement.DetermineParameters(); builder.AddControl(stickName + "/x") - .WithFormat(xElement.isSigned ? InputStateBlock.FormatSBit : InputStateBlock.FormatBit) + .WithFormat(xElement.DetermineFormat()) .WithByteOffset((uint)(xElement.reportOffsetInBits / 8 - byteOffset)) .WithBitOffset((uint)(xElement.reportOffsetInBits % 8)) .WithSizeInBits((uint)xElement.reportSizeInBits) @@ -394,7 +394,7 @@ public InputControlLayout Build() .WithProcessors(xElement.DetermineProcessors()); builder.AddControl(stickName + "/y") - .WithFormat(yElement.isSigned ? InputStateBlock.FormatSBit : InputStateBlock.FormatBit) + .WithFormat(yElement.DetermineFormat()) .WithByteOffset((uint)(yElement.reportOffsetInBits / 8 - byteOffset)) .WithBitOffset((uint)(yElement.reportOffsetInBits % 8)) .WithSizeInBits((uint)yElement.reportSizeInBits)