touchscreen does not work after the first touch ended

Hi,
I’ve been using Touchscreen to simulte player inputs recently. And I have encountered this for several days. My code is like this:

Touchscreen device = InputSystem.AddDevice<Touchscreen>(deviceName);

...

void TestClick()
{
            InputSystem.QueueStateEvent(device, new TouchState
            {
                touchId = touchId,
                phase = UnityEngine.InputSystem.TouchPhase.Began,
                position = pos,
                isPrimaryTouch = true,
            });
            InputSystem.QueueStateEvent(device, new TouchState
            {
                isTap = true,
                touchId = touchId++,
                phase = UnityEngine.InputSystem.TouchPhase.Ended,
                position = pos,
            });
}

Then when i call TestClick() the firt time, the click event works right. The gameobject responds the click. Everything is right. But later (i.e. 1 second later) no matter how many times I call TestClick(), it doesn’t work.

After working into this for days, I find that if I change the code like this:

void TestClick()
{
            InputSystem.RemoveDevice(device);
            device = InputSystem.AddDevice<Touchscreen>(deviceName);
            InputSystem.QueueStateEvent(device, new TouchState
            {
                touchId = touchId,
                phase = UnityEngine.InputSystem.TouchPhase.Began,
                position = pos,
                isPrimaryTouch = true,
            });
            InputSystem.QueueStateEvent(device, new TouchState
            {
                isTap = true,
                touchId = touchId++,
                phase = UnityEngine.InputSystem.TouchPhase.Ended,
                position = pos,
            });
}

Every time when I call TestClick(), I remove the device and then add it. The click works all the time.

I can’t tell why this happen, even if I read all the api documents about Touchscreen, TouchState etc.
Thanks for helping.

However, here comes another stack error when I remove and add device each time before click.

InvalidOperationException while executing 'canceled' callbacks of 'UI/Click[/Touchscreen/touch0/press,/Touchscreen/touch1/press,/Touchscreen/touch2/press,/Touchscreen/touch3/press,/Touchscreen/touch4/press,/Touchscreen/touch5/press,/Touchscreen/touch6/press,/Touchscreen/touch7/press,/Touchscreen/touch8/press,/Touchscreen/touch9/press,/Touchscreen/touch0/press,/Touchscreen/touch1/press,/Touchscreen/touch2/press,/Touchscreen/touch3/press,/Touchscreen/touch4/press,/Touchscreen/touch5/press,/Touchscreen/touch6/press,/Touchscreen/touch7/press,/Touchscreen/touch8/press,/Touchscreen/touch9/press]'
UnityEngine.InputSystem.InputManager:RemoveDevice(InputDevice, Boolean)
Game.Common.AutoQATouchMgr:TestClick()
Game.Common.AutoQATouchMgr:ClickScreenPos(Single, Single)
InvalidOperationException: Cannot query value of control '/Touchscreen/touch0/touchId' before 'autoqaDevice1' has been added to system!
UnityEngine.InputSystem.InputControl.ResolveDeviceIndex () (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputControl.get_currentStatePtr () (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputControl`1[TValue].ReadValue () (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.GetPointerStateIndexFor (UnityEngine.InputSystem.InputControl control) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.GetPointerStateFor (UnityEngine.InputSystem.InputAction+CallbackContext& context) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.OnLeftClick (UnityEngine.InputSystem.InputAction+CallbackContext context) (at <00000000000000000000000000000000>:0)
System.Action`1[T].Invoke (T obj) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.InlinedArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionState.CallActionListeners (System.Int32 actionIndex, UnityEngine.InputSystem.InputActionMap actionMap, UnityEngine.InputSystem.InputActionPhase phase, UnityEngine.InputSystem.Utilities.InlinedArray`1[System.Action`1[UnityEngine.InputSystem.InputAction+CallbackContext]]& listeners, System.String callbackName) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionState.ChangePhaseOfAction (UnityEngine.InputSystem.InputActionPhase newPhase, UnityEngine.InputSystem.InputActionState+TriggerState& trigger, UnityEngine.InputSystem.InputActionPhase phaseAfterPerformedOrCanceled) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionState.ResetActionState (System.Int32 actionIndex, UnityEngine.InputSystem.InputActionPhase toPhase) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionState.DisableAllActions (UnityEngine.InputSystem.InputActionMap map) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionMap.ResolveBindings () (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionMap.LazyResolveBindings () (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputActionState.OnDeviceChange (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.InputDeviceChange change) (at <00000000000000000000000000000000>:0)
UnityEngine.InputSystem.InputManager.RemoveDevice (UnityEngine.InputSystem.InputDevice device, System.Boolean keepOnListOfAvailableDevices)
1 Like

Could anyone help me please…

bump this

I have exactly the same issue.
We disable the UI screen and we get this exception report if the player is clicking on the input UI.

Is there a solution for the problem?

I feel like the new inputsystem is still a hot potato. I don’t know dude.