OnScreenControl error with custom device in 1.1.1

Hello

I just updated to version 1.1.1 and now I’m getting an some errors when I try to use on screen controls with a custom device.

I’ve tested it in a new project (2020.3.18f1) using the Custom Device and On-Screen Controls samples and get the same result.

If I open the OnScreenControlsSample scene and change the control path for one of the buttons to a CustomDevice button I get the following errors:

NullReferenceException while resolving binding 'Submit:*/{Submit}' in action map 'DefaultInputActions (UnityEngine.InputSystem.InputActionAsset):UI'
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1378)
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputControlPath.MatchByUsageAtDeviceRootRecursive[TControl] (UnityEngine.InputSystem.InputDevice device, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:920)
UnityEngine.InputSystem.InputControlPath.MatchControlsRecursive[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:897)
UnityEngine.InputSystem.InputControlPath.TryFindControls[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:663)
UnityEngine.InputSystem.InputManager.GetControls[TControl] (System.String path, UnityEngine.InputSystem.InputControlList`1[TControl]& controls) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputManager.cs:952)
UnityEngine.InputSystem.InputSystem.FindControls[TControl] (System.String path, UnityEngine.InputSystem.InputControlList`1[TControl]& controls) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputSystem.cs:2226)
UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputBindingResolver.cs:281)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable() (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1378)
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputControlPath.MatchByUsageAtDeviceRootRecursive[TControl] (UnityEngine.InputSystem.InputDevice device, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:920)
UnityEngine.InputSystem.InputControlPath.MatchControlsRecursive[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:897)
UnityEngine.InputSystem.InputControlPath.TryFindControls[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:663)
UnityEngine.InputSystem.InputManager.GetControls[TControl] (System.String path, UnityEngine.InputSystem.InputControlList`1[TControl]& controls) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputManager.cs:952)
UnityEngine.InputSystem.InputSystem.FindControls[TControl] (System.String path, UnityEngine.InputSystem.InputControlList`1[TControl]& controls) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputSystem.cs:2226)
UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputBindingResolver.cs:571)
UnityEngine.InputSystem.InputActionMap.ResolveBindings () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputActionMap.cs:1169)
UnityEngine.InputSystem.InputActionMap.ResolveBindingsIfNecessary () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputActionMap.cs:1065)
UnityEngine.InputSystem.InputAction.Enable () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputAction.cs:866)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.EnableInputAction (UnityEngine.InputSystem.InputActionReference inputActionReference) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1468)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.EnableAllActions () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1423)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.OnEnable () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:1378)

Has anyone have any ideas?

Cheers

So, it looks like this is probably an issue with the OnScreenControl class. I created a custom touch button class and it seems to be working.

public class OSGButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
    {
        [InputControl(layout = "Button")]
        [SerializeField]
        private string m_ControlPath;

        private InputControl inputControl;

        private void OnEnable()
        {
            inputControl = InputSystem.FindControl(m_ControlPath);
        }

        public void OnPointerUp(PointerEventData data)
        {
            SendValueToControl(0.0f);
        }

        public void OnPointerDown(PointerEventData data)
        {
            SendValueToControl(1.0f);
        }

        public void OnPointerExit(PointerEventData eventData)
        {
            if (isPressed)
            {
                OnPointerUp(eventData);
            }
        }

        private void SendValueToControl(float v)
        {
            InputEventPtr inputEventPtr;

            using (StateEvent.From(inputControl.device, out inputEventPtr))
            {
                inputControl.WriteValueIntoEvent(v, inputEventPtr);
                InputSystem.QueueEvent(inputEventPtr);
            }
        }
    }

Is your custom device registered before UnityEngine.InputSystem.UI.InputSystemUIInputModule:OnEnable() is called?

My test setup was in a new project using the Custom Device and On-Screen Control samples from the package manager.

Enabling the InputSystemUIInputModule after the device threw up the same errors.

Enabling the InputSystemUIInputModule before the device gives a different error.

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputControlPath.MatchByUsageAtDeviceRootRecursive[TControl] (UnityEngine.InputSystem.InputDevice device, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:920)
UnityEngine.InputSystem.InputControlPath.MatchControlsRecursive[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath, UnityEngine.InputSystem.InputControlList`1[TControl]& matches, System.Boolean matchMultiple) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:897)
UnityEngine.InputSystem.InputControlPath.TryFindControl[TControl] (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:630)
UnityEngine.InputSystem.InputControlPath.TryFindControl (UnityEngine.InputSystem.InputControl control, System.String path, System.Int32 indexInPath) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Controls/InputControlPath.cs:568)
UnityEngine.InputSystem.InputActionState.CanUseDevice (UnityEngine.InputSystem.InputDevice device) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputActionState.cs:287)
UnityEngine.InputSystem.InputActionState.OnDeviceChange (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.InputDeviceChange change) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Actions/InputActionState.cs:3869)
UnityEngine.InputSystem.InputManager.NotifyUsageChanged (UnityEngine.InputSystem.InputDevice device) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputManager.cs:1001)
UnityEngine.InputSystem.InputManager.AddDeviceUsage (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.Utilities.InternedString usage) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputManager.cs:983)
UnityEngine.InputSystem.InputSystem.AddDeviceUsage (UnityEngine.InputSystem.InputDevice device, System.String usage) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/InputSystem.cs:2053)
UnityEngine.InputSystem.OnScreen.OnScreenControl.SetupInputControl () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/OnScreen/OnScreenControl.cs:142)
UnityEngine.InputSystem.OnScreen.OnScreenControl.OnEnable () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Plugins/OnScreen/OnScreenControl.cs:213)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

It seems like a problem related to setting the device usage?

@David_Faulkner I don’t immediately see what could be broken, would you mind to file a bug report (help->report a bug)? thanks!