Touch input goes through UI and more

*Might have put this in the wrong section…

Hello everyone!

Touch input goes through UI and more

I’m bringing this up again, many people still have problems with this and do not have time to convert their game into the new raycasting thingy.

I am making this 3D tower defence game and when I build the game on my android device, touch input goes through panels, buttons, 3D objects and everything. For example it can go through a toggle, button below it and a panel, and activate something else below it in the game. With one touch.

Im using the latest version of unity.

I have searched and read everything related to this problem including youtube videos. I tried almost everthing and I still have the same problem. I have tried understanding raycasting and that would take forever to implement and understand in my complex game, wich was working perfectly in older versions of Unity.

It is almost 2018 and I know this problem is old, what is the easiest fix for ANDROID devices and most recent solution? The various solutions from 2014-2015 is not working. All I want is to deactivate ANDROID touch behind a object, simple as that.

Nothing in this thread works for me: Android touches pass through UI elements - Questions & Answers - Unity Discussions

I have tried using theese, on buttons, panels, gameobjects and such:
//EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)
//EventSystem.current.IsPointerOverGameObject(fingerId)
//EventSystem.current.IsPointerOverGameObject()

I did not find a working solution for my game.

Also I do not want something that runs in the update function (maybe this is where I will have to settle and change my mind…)… :

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class MouseExample : MonoBehaviour
{
    void Update()
    {
        // Check if the left mouse button was clicked
        if (Input.GetMouseButtonDown(0))
        {
            // Check if the mouse was clicked over a UI element
            if (EventSystem.current.IsPointerOverGameObject())
            {
                Debug.Log("Clicked on the UI");
            }
        }
    }
}

Again: * All I want is to deactivate ANDROID touch behind a UI object, simple as that.

Help

Best
Regards

Here is the way I handle it in my games. Each part of my UI has a UI zone associated with it, whether that UI component is static or dynamic in the game. A UI zone is essentially a simple polygon class with a contains method, where the polygon follows the shape of a parent UI element such as a panel. I handle all game input in an central input controller (to facilitate user defined key mappings on PC, etc). The input controller queries a UI manager which maintains a list of all UI zones that are active at any time. When a click or touch happens in the game, the input manager asks if a click/touch is in an active UI zone. It it is, it is ignored in the game world. For dynamic parts of the UI, when they each are activated, they add a UI zone to the list of active zones that are checked and remove their associated zone when they are deactivated. Modal dialogs are just handled with a boolean that is set to true whenever a modal dialog is open. This flag causes all input in the game world to be ignored when it is true. Overall, this approach has worked well. It is very easy to implement provided you take a centralized approach to input management. This means I am not reading game input all over the place but rather within the input manager. Any game object or component that needs to read input, reads that input via a reference to the input manager. I started doing this long ago to make it possible to dynamic change input key bindings in PC games and have just stuck with it. The other reason I have stuck with it is at times using the event system has failed.

2 Likes