Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Selective Multitouch - Disable Multitouch on UI

Discussion in 'UGUI & TextMesh Pro' started by d4n3x, Mar 3, 2020.

  1. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    24
    Dear community,

    i have an major problem in my App. I have developed a crossplatform application with the native unity ui. Till now everything is working fine. But now i want to limit the touchcount on the UI to 1 so that it is impossible to click 2 Buttons at the same time. First thought was to set the Input.multitouchEnabled = false, which indeed works. But sadly I need the multitouch outside the UI for scale gestures and the XR Interaction Toolkit.

    Are there any ideas to limit the touchcount only in the UI to 1?
    Would really need the help of u.

    Thanks in advance,
    Danex
     
  2. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    24
    Success - I found a working solution for me.
    Key was to edit the Standalone Input module. Even this is sure not the best solution - it works.

    So for this u have to add following lines to the Standalone Input module:


    Code (CSharp):
    1.         private bool ProcessTouchEvents()
    2.         {
    3.             int touchCount = input.touchCount;
    4.             if(touchCount > 1)
    5.             {
    6.                 for (int i = 0; i < touchCount; ++i)
    7.                 {
    8.                     if(EventSystem.current.IsPointerOverGameObject(i))
    9.                     {
    10.                         touchCount = 1;
    11.                         break;
    12.                     }
    13.                 }          
    14.             }
    15.  
    16.             for (int i = 0; i < touchCount; ++i)
    17.             {
    18.                 Touch touch = input.GetTouch(i);
    19. .
    20. .
    21. .
    22. .
    This will limit the touches on the UI to 1 and outside the UI multitouch still works!!

    EDIT:
    To be clean - copy the Standard Input Module of your current Unity Version in to your Repository and edit the copied one and use that in your project.


    Greets,
    Danex
     
    Last edited: Mar 3, 2020
    BeeNvizzio likes this.
  3. thientv84

    thientv84

    Joined:
    Mar 2, 2013
    Posts:
    4
  4. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Hey @d4n3x I was reading this and I couldn't understand your solution. Can you clarify?
    Sorry for bringing this post back to life...
    You downloaded the Standard (standalone?) Input Module from a decompiled unity repo and changed the code?
    How did you add that back into unity? Is it a separate package? Does that change any of the default Input class uses?