How to accept swipe input when already touching with one finger.

I am using the “new” input system and have 2 joysticks on screen with the on-screen stick component script. They work great even when handling both joysticks being used at once.


My layout for this mobile game is the top half of the screen is for swiping, the bottom left is a canvas for the movement joystick, and the bottom right is a canvas for the aiming joystick.

My swipe detection also works well on its own. However, I didnt recognize this until building to a phone today but my swipe detection script is currently overridden by touching the joysticks and it kills the script since I’m already touching the screen. How can i change my script or better utilize the input system to handle the swipe input?:

private void OnEnable()
    {
        inputManager.OnStartTouch += SwipeStart;
        inputManager.OnEndTouch += SwipeEnd;
    }

    private void OnDisable()
    {
        inputManager.OnStartTouch -= SwipeStart;
        inputManager.OnEndTouch -= SwipeEnd;
    }

    private void SwipeStart(Vector2 position, float time)
    {
        if (position.y < Screen.height / 2f)
        {
            return;
        }
        startPosition = position;
        startTime = time;
    }

    private void SwipeEnd(Vector2 position, float time)
    {
        endPosition = position;
        endTime = time;
        DetectSwipe();
    }

    private void DetectSwipe()
    {
        if (Vector3.Distance(startPosition,endPosition) >= minDistance && (endTime - startTime) <= maxTime)
        {
            playerController.SwapWeapons();
            Debug.DrawLine(startPosition, endPosition, Color.red,5f);
        }
    }
}

@Fulcrum_Games I don’t know about your code but as my knowledge your issue same as i am facing with touchscreen, However after about one week or more days today the following solution works for me. in my fps game with unity new input system on screen buttons, joystick and swipe touch field. When we First press button/joystick then update the touch FingerIndx =0 and then 2nd for swipe touch fingerIndx =1 and so on…
For TouchPad Create Ui/ Image in canvas set color/ alpha to 0, for swipe touch field.
And add the script on it.

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using EnhancedTouch = UnityEngine.InputSystem.EnhancedTouch;

public class TouchPad : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [SerializeField] private float touchSpeed = 30f;
    private bool isPressed;
    private int pointerId, currentId;
    [HideInInspector] public Vector2 deltaPosition; //value to use for swipe
    public static TouchPad Instance { get; set; } //for singletons
    private void Awake()
    {
        Instance = this;
    }
    private void OnEnable()
    {
        //Enable support for the new Enhanced Touch API and testing with the mouse
        EnhancedTouch.EnhancedTouchSupport.Enable();
        EnhancedTouch.TouchSimulation.Enable();
        EnhancedTouch.Touch.onFingerDown += Touch_onFingerDown;
    }
    private void OnDisable()
    {
        EnhancedTouch.Touch.onFingerDown -= Touch_onFingerDown;
        EnhancedTouch.EnhancedTouchSupport.Disable();
        EnhancedTouch.TouchSimulation.Disable();
    }
    public void OnPointerDown(PointerEventData data) //when pointer has pressed the uiObj
    {
        if (isPressed) {
            return;
        }
        isPressed = true;
        foreach (var touch in EnhancedTouch.Touch.activeTouches) {
            if(touch.finger.index==currentId)
                pointerId = touch.finger.index;
        }
        deltaPosition = Vector2.zero;
    }
    private void Touch_onFingerDown(EnhancedTouch.Finger obj)
    {
        currentId = obj.index;
    }
    public void OnPointerUp(PointerEventData data) //when pointer has release uiObj
    {
        if (!isPressed) {
            return;
        }
        isPressed = false;
        deltaPosition = Vector2.zero;
    }
    void FixedUpdate()
    {
        if (isPressed)
        { 
		//use pointerId as your requirment for low-level or high-level touch support.
		//here example of high level touch for delta swip position
            if(pointerId >=0 && pointerId <= EnhancedTouch.Touch.activeTouches.Count)
            {
                deltaPosition.x = EnhancedTouch.Touch.activeTouches[pointerId].delta.x * touchSpeed * Time.deltaTime;
                deltaPosition.y = EnhancedTouch.Touch.activeTouches[pointerId].delta.y * touchSpeed * Time.deltaTime;
            }
            else {
                deltaPosition = new Vector2(EnhancedTouch.Touch.activeTouches[pointerId].delta.x, EnhancedTouch.Touch.activeTouches[pointerId].delta.y);
            }
        }
        else {
            deltaPosition = new Vector2();
        }
    }
}

Now build project for mobile phone test on touchscreen.
Sorry its too late for you, but i hope it helps if other member facing the same issue