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
INPUT ACTIONS SETTINGS
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…