Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question touchscreen does not work after the first touch ended

Discussion in 'Input System' started by codyWjr, Aug 8, 2020.

  1. codyWjr

    codyWjr

    Joined:
    Aug 8, 2020
    Posts:
    3
    Hi,
    I've been using Touchscreen to simulte player inputs recently. And I have encountered this for several days. My code is like this:
    Code (CSharp):
    1. Touchscreen device = InputSystem.AddDevice<Touchscreen>(deviceName);
    2.  
    3. ...
    4.  
    5. void TestClick()
    6. {
    7.             InputSystem.QueueStateEvent(device, new TouchState
    8.             {
    9.                 touchId = touchId,
    10.                 phase = UnityEngine.InputSystem.TouchPhase.Began,
    11.                 position = pos,
    12.                 isPrimaryTouch = true,
    13.             });
    14.             InputSystem.QueueStateEvent(device, new TouchState
    15.             {
    16.                 isTap = true,
    17.                 touchId = touchId++,
    18.                 phase = UnityEngine.InputSystem.TouchPhase.Ended,
    19.                 position = pos,
    20.             });
    21. }
    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:
    Code (CSharp):
    1. void TestClick()
    2. {
    3.             InputSystem.RemoveDevice(device);
    4.             device = InputSystem.AddDevice<Touchscreen>(deviceName);
    5.             InputSystem.QueueStateEvent(device, new TouchState
    6.             {
    7.                 touchId = touchId,
    8.                 phase = UnityEngine.InputSystem.TouchPhase.Began,
    9.                 position = pos,
    10.                 isPrimaryTouch = true,
    11.             });
    12.             InputSystem.QueueStateEvent(device, new TouchState
    13.             {
    14.                 isTap = true,
    15.                 touchId = touchId++,
    16.                 phase = UnityEngine.InputSystem.TouchPhase.Ended,
    17.                 position = pos,
    18.             });
    19. }
    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.
     
  2. codyWjr

    codyWjr

    Joined:
    Aug 8, 2020
    Posts:
    3
    However, here comes another stack error when I remove and add device each time before click.

    Code (CSharp):
    1. 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]'
    2. UnityEngine.InputSystem.InputManager:RemoveDevice(InputDevice, Boolean)
    3. Game.Common.AutoQATouchMgr:TestClick()
    4. Game.Common.AutoQATouchMgr:ClickScreenPos(Single, Single)

    Code (CSharp):
    1. InvalidOperationException: Cannot query value of control '/Touchscreen/touch0/touchId' before 'autoqaDevice1' has been added to system!
    2. UnityEngine.InputSystem.InputControl.ResolveDeviceIndex () (at <00000000000000000000000000000000>:0)
    3. UnityEngine.InputSystem.InputControl.get_currentStatePtr () (at <00000000000000000000000000000000>:0)
    4. UnityEngine.InputSystem.InputControl`1[TValue].ReadValue () (at <00000000000000000000000000000000>:0)
    5. UnityEngine.InputSystem.UI.InputSystemUIInputModule.GetPointerStateIndexFor (UnityEngine.InputSystem.InputControl control) (at <00000000000000000000000000000000>:0)
    6. UnityEngine.InputSystem.UI.InputSystemUIInputModule.GetPointerStateFor (UnityEngine.InputSystem.InputAction+CallbackContext& context) (at <00000000000000000000000000000000>:0)
    7. UnityEngine.InputSystem.UI.InputSystemUIInputModule.OnLeftClick (UnityEngine.InputSystem.InputAction+CallbackContext context) (at <00000000000000000000000000000000>:0)
    8. System.Action`1[T].Invoke (T obj) (at <00000000000000000000000000000000>:0)
    9. 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)
    10. 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)
    11. UnityEngine.InputSystem.InputActionState.ChangePhaseOfAction (UnityEngine.InputSystem.InputActionPhase newPhase, UnityEngine.InputSystem.InputActionState+TriggerState& trigger, UnityEngine.InputSystem.InputActionPhase phaseAfterPerformedOrCanceled) (at <00000000000000000000000000000000>:0)
    12. UnityEngine.InputSystem.InputActionState.ResetActionState (System.Int32 actionIndex, UnityEngine.InputSystem.InputActionPhase toPhase) (at <00000000000000000000000000000000>:0)
    13. UnityEngine.InputSystem.InputActionState.DisableAllActions (UnityEngine.InputSystem.InputActionMap map) (at <00000000000000000000000000000000>:0)
    14. UnityEngine.InputSystem.InputActionMap.ResolveBindings () (at <00000000000000000000000000000000>:0)
    15. UnityEngine.InputSystem.InputActionMap.LazyResolveBindings () (at <00000000000000000000000000000000>:0)
    16. UnityEngine.InputSystem.InputActionState.OnDeviceChange (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.InputDeviceChange change) (at <00000000000000000000000000000000>:0)
    17. UnityEngine.InputSystem.InputManager.RemoveDevice (UnityEngine.InputSystem.InputDevice device, System.Boolean keepOnListOfAvailableDevices)
     
    Miguel_FirstLight likes this.
  3. codyWjr

    codyWjr

    Joined:
    Aug 8, 2020
    Posts:
    3
    Could anyone help me please....
     
  4. Miguel_FirstLight

    Miguel_FirstLight

    Joined:
    Apr 9, 2020
    Posts:
    19
    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?
     
  5. engelhard90

    engelhard90

    Joined:
    Oct 2, 2018
    Posts:
    19
    I feel like the new inputsystem is still a hot potato. I don't know dude.