Touchscreen game's input goes through UI (NEW INPUT SYSTEM)

Hi i’m working on a project with a touchscreen handled input (target is mobile) with the new input system, im having a problem where my touch goes through UI and clicks both the map and the UI objects… i’ve tried the usual solutions but nothing… i’m starting to suspect that’s a setting issue too.

This is my project so far:

PLAYER SETTINGS
image

INPUT ACTIONS SETTINGS
image

MAIN CAMERA

INPUT MANAGER

SAMPLE OF CANVAS WITH THIS PROBLEM


SCRIPT WHERE I HANDLE TOUCH

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.UIElements;

public class PointAndClick_Movement : MonoBehaviour
{
    private PlayerInput _playerInput;
    private InputAction _touchMoveAction;
    private bool _isClickOverUi;

    private void Update()
    {
      //does basically nothing
        _isClickOverUi = EventSystem.current.IsPointerOverGameObject();
    }

    void Awake()
    {
        _playerInput = GetComponent<PlayerInput>();
        _touchMoveAction = _playerInput.actions["ClickOnMap"];
    }

    private void OnEnable()
    {
        //Lo eseguiamo solo quando performato
        _touchMoveAction.performed += MoveActionRoutine;
        EventManagerOverworld.QuizStartButtonClicked += (_) => SetMovement(false);
        EventManagerOverworld.QuizOver += () => SetMovement(true);
    }

    private void OnDisable()
    {
        //Togliamo l'evento
        _touchMoveAction.performed -= MoveActionRoutine;
        EventManagerOverworld.QuizStartButtonClicked -= (_) => SetMovement(false);
        EventManagerOverworld.QuizOver -= () => SetMovement(true);
    }

    private void OnDestroy()
    {
        _touchMoveAction.performed -= MoveActionRoutine;
        EventManagerOverworld.QuizStartButtonClicked -= (_) => SetMovement(false);
        EventManagerOverworld.QuizOver -= () => SetMovement(true);
    }

    /// <summary>
    /// Used to disable or enable movement routine.
    /// doesn't disable touch
    /// </summary>
    /// <param name="isMovementEnabled"></param>
    public void SetMovement(bool isMovementEnabled)
    {
        //NOTE - sarebbe da controllare che non ci siano doppioni
        if (isMovementEnabled)
            _touchMoveAction.performed += MoveActionRoutine;
        else
            _touchMoveAction.performed -= MoveActionRoutine;
    }

    private void MoveActionRoutine(InputAction.CallbackContext _)
    {
        Ray ray = Camera.main.ScreenPointToRay(_touchMoveAction.ReadValue<Vector2>());
        if (Physics.Raycast(ray, out RaycastHit hit, 1000f) && !_isClickOverUi)
        {
            EventManagerOverworld.OnClickOnOverworld(hit.point);
        }
    }
}

What am i missing? If i try to disable the touch input the UI still works so i was wondering if i wan’t simulating touchscreen from the game editor? I really don’t know what to do…

Solved the problem, I tried the man’s way and decided to read a bit more the documentation and in the end i didn’t even need to, there was a sample on how to handle this stuff in the package:

image

seeing how they handled it i modified my code to avoid callsback:

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;

public class PointAndClick_Movement : MonoBehaviour
{
    private PlayerInput _playerInput;
    private InputAction _touchMoveAction;
    private bool _isClickOverUi;

    private void Update()
    {
        if (_touchMoveAction.WasPerformedThisFrame() && !IsPointerOverUI())
            MoveActionRoutine();
    }

    void Awake()
    {
        _playerInput = GetComponent<PlayerInput>();
        _touchMoveAction = _playerInput.actions["ClickOnMap"];
    }

    private void MoveActionRoutine()
    {
        Ray ray = Camera.main.ScreenPointToRay(_touchMoveAction.ReadValue<Vector2>());
        if (Physics.Raycast(ray, out RaycastHit hit, 1000f) && !_isClickOverUi)
        {
            EventManagerOverworld.OnClickOnOverworld(hit.point);
        }
    }

    private bool IsPointerOverUI()
    {
        // check if the primary pointer is currently over a UI object.
        return EventSystem.current.IsPointerOverGameObject();
    }
}

i think the only real difference is that now the frame where the click was performed and the check on IsPointerOverGameObject is in sync.

After this i had the reverse problem, i needed to be able to click through some UI but it was simple to handle it:

  1. CAN CLICK THROUGH ALL THE UI: just disable the raycaster on the canvas
  2. NEED TO CLICK ON SOME UI: my case, i had a label that had to be click through (my player moves on the map with a point and click movement) and when you go near a button spwan that needs to be clickable.
    To do so i just removed the text wrap from the label and resized the canvas and the label to be
    1px x 1px, technically speaking the player could still click on a point and not being able to move because it collide with the canvas but it’s so small that’s nearly impossible.