Issues with Input Control Offset while creating custom layouts

Hi everyone,

I faced an issue regarding the offset in input controls while I am trying to create a custom layout for my device (its a Logitech controller).

The reason I am creating a custom layout is because I want unity to register my Logitech controller as a gamepad and not a joystick. I was partially successful but I am facing issues with some specific buttons on my controller. I was able to solve these issues once I used the correct offset while creating the controls for my layout.

The thing is, I am seeing 3 different values for the offset, and I am not sure which one should I use, and when, and how they relate to one another.

  • Input Debugger shows a 5 in the offset.
  • InputStateBlock from my Input control returns numbers in the range of 120s, so it will be 125 in the offset.
  • Layout Json (copying the json of the layout), it will some times show 5 or 4294967295.

Questions:

  • Which one of these values I should use while trying to build a layout for my controller. I tried using the layout offset, but it didn’t work. The json was correct but the unity input debugger showed 0 in the offset.
curBuilder.AddControl(curButtonName)
                .WithByteOffset(deviceButtonInfo.offset)
                .WithBitOffset(deviceButtonInfo.bit)
                .WithSizeInBits(deviceButtonInfo.sizeInBits)
                .WithFormat(deviceButtonInfo.format);
  • I also noticed that all these offsets have the same number in the end, so 125, 5, 4294967295. Is it correct to assume that I can just take the % 10 of any of these offsets and I will get the correct offset? this seemed to work but I haven’t tested it for all buttons on my controller.

I am kinda of confused, and any help would be greatly appreciated. As far as I understand, offset tells input system where to start looking in the state buffer. So any clarification will be helpful.

Snippet of the code:

//--- in awake
InputSystem.onAnyButtonPress.Call(OnDeviceButtonSetup);
 
//---
     private void OnDeviceButtonSetup(InputControl inputControl) {

            string curControlPath = inputControl.path.Replace($"/{curDeviceSetup.name}/", "");
      
            Debug.Log($"Control {inputControl.path}");
      
            InputStateBlock tempDeviceInfo = inputControl.stateBlock;
            Debug.Log($"--- StateBlock, offset: {tempDeviceInfo.byteOffset}, bit: {tempDeviceInfo.bitOffset}, size: {tempDeviceInfo.sizeInBits}, format: {tempDeviceInfo.format} ");
      
            InputControlLayout.ControlItem deviceButtonInfo = oldLayout.controls.FirstOrDefault(c => c.name == curControlPath);
      
            if (deviceButtonInfo.name != curControlPath) {
                Debug.LogWarning($"Couldn't find the input control name {deviceButtonInfo.name}");
                return;
            }
      
            Debug.Log($"---- Layout, offset: {deviceButtonInfo.offset}, bit: {deviceButtonInfo.bit}, size: {deviceButtonInfo.sizeInBits}, format: {deviceButtonInfo.format}, layout: {deviceButtonInfo.layout}");
      
        }

Update. I think I figured some stuff out.

  • The offset in the Input Debugger is absolute offset, so if the offset on stick/up shows 2 in the InputDebugger, then that offset is the sum of its offset and its parent offsets. So, if the stick has offset 1, then you will want the offset for your stick/up to be in your layoutJson to be 2-1 which is 1.
  • Also, it seems that 4294967295 is the same as 0 offset. Not sure if there is a technical difference but replacing 4294967295 with 0 in my layoutJson seemed to work.