InputSystem.QueueDeltaStateEvent for bitfield

I have a custom device/layout. My button states are stored in a ushort bitfield.
InputSystem.QueueDeltaStateEvent throws an error.
Is there a workaround? Thanks much!

[InputControl(name = "buttonB", layout = "Button", bit = 1)]
public ushort buttons;```

```InvalidOperationException: Cannot send delta state events against bitfield controls: Button:/AxisOrangeInputDevice/buttonB```

Got same issue and this the only place on Internet where the subject is raised so I will try to answer the question for other people who encounter the same issue.

This error messages is triggered from this condition:

if (control.stateBlock.bitOffset != 0)
    throw new InvalidOperationException($"Cannot send delta state events against bitfield controls: {control}");

So, you just cannot use InputSystem.QueueDeltaStateEvent on a InputControl that use bitfields (that was the case in your example with bit = 0 and bit = 1.

In my own case, it was due to UnityEngine.InputSystem.TrackedDevice.

[InputControl(synthetic = true)]
public ButtonControl isTracked { get; private set; }

The message appeared when trying to set the delta state event on this InputControl. However there is no bit field manipulation so I do not understand why. When debugging, its stateBlock.bitOffset is 5.

My own code is based on Unity.XR.Hands.XRHandDevice and they use InputSystem.InputSystem.QueueDeltaStateEvent(isTracked, false); with no problem, but I cannot.

Well, a workaround is to get ride of InputSystem.QueueDeltaStateEvent and use StateEvent.From and InputControl.WriteValueIntoEvent.
Here is an example:

using (StateEvent.From(this, out InputEventPtr eventPtr))
{
...
devicePosition.WriteValueIntoEvent(position, eventPtr);
deviceRotation.WriteValueIntoEvent(rotation, eventPtr);
isTracked.WriteValueIntoEvent(isDeviceTracked ? 1.0f : 0.0f, eventPtr);
...
}

Be really careful on the type you use when using WriteValueIntoEvent. For example, the ButtonControl use a float internally so you may want to set:
buttonControl.WriteValueIntoEvent(isPressed ? 1.0f : 0.0f); instead of buttonControl.WriteValueIntoEvent(isPressed);

I had the same issue and accidentally solved it.
Here’s my code that gives InvalidOperationException: Cannot send delta state events against bitfield controls for InputSystem.QueueDeltaStateEvent(poking, isPoking);. However, InputSystem.QueueDeltaStateEvent(grabbableGrabbed, isGrabbableGrabbed); was working fine. This is weird because poking and grabbableGrabbed have the same types.

My solution is adding the offset = 0 to the [InputControl] tag:

    [InputControl(offset = 0)]
    public ButtonControl grabbableGrabbed { get; private set; }
   
    [InputControl(offset = 1)]
    public ButtonControl poking { get; private set; }

and updating works fine…

InputSystem.QueueDeltaStateEvent(grabbableGrabbed, isGrabbableGrabbed);
InputSystem.QueueDeltaStateEvent(poking, isPoking);