Can a Vector2 value be read from OneModifierComposite?

The documentation for OneModifierComposite has this example binding a look action:

lookAction.AddCompositeBinding("OneModifier")
    .With("Modifier", "<Keyboard>/alt")
    .With("Binding", "<Mouse>/delta")

However, trying to poll the action directly for a value

var look = lookAction.ReadValue<Vector2>()

Throws a NullReferenceException

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Packages/com.unity.inputsystem@1.1.0-preview.2/InputSystem/Actions/InputActionState.cs:2248)
UnityEngine.InputSystem.InputAction.ReadValue[TValue] () (at Packages/com.unity.inputsystem@1.1.0-preview.2/InputSystem/Actions/InputAction.cs:920)

How then should a Vector2 value be read from the OneModifierComposite?
Or, is the look action example misleading and should we use a custom composite instead?

1 Like

I’m running into this same issue right now, I would figure the modifier just acts as a gate & the binding is what controls the type returned. In my case I’ve got Position as the binding, but can’t seem to read a Vector2 from it

Indeed a bug. Reading the value through InputAction.ReadValue() does the right thing but reading it through InputAction.CallbackContext.ReadValue() in a callback throws. Fixed here.

1 Like

when will this fix be released via the package manager update? Is there a work-around to get values from a composite input in the meantime?

Solved this by using ReadValueAsObject on the composite with modifier. Returned Null if no modifier was engaged and the Vector2 if it was.