Drag threshold default 10 now?!

So the major issue with Drag Threshold on the event system is it is not DPI dependant as it should be.
But is that why is was changed from 5 to 10 (in 2018 I think)?

10 is probably right on 4k desktop and maybe on some mobile devices, it is kind of big on a 1080 desktop where the old 5 would make more sense.

Best would be best to set it in DPI not pixels

Here’s what I ended up doing in my game:

using UnityEngine;
using UnityEngine.EventSystems;

// Attach this to the object with your EventSystem and it will overwrite the Drag Threshold
// on Start to change it relative to the device's current DPI, allowing it to be specified
// in terms of physical distance instead of pixels
public class PhysicalDragThreshold : MonoBehaviour
{
    public float inchesDragThreshold = .05f;
    public float defaultDPI = 100;    // DPI to assume if we can't detect the device's

    // if touchThreshMultiplier > 1, then the threshold will be higher for touches than for
    // mouse input.  This works by checking the number of active touches every frame...
    public float touchThreshMultiplier = 4;

    private EventSystem evSys;


    void Start ()
    {
        evSys = GetComponent<EventSystem>();
        SetDragThreshold();
    }

    private void Update()
    {
        if (!Mathf.Approximately(touchThreshMultiplier, 1))
        {
            SetDragThreshold();
        }
    }

    public void SetDragThreshold()
    {
        if (evSys != null)
        {
            float dpi = Screen.dpi;
            if (dpi < 10) dpi = defaultDPI;

            if (Input.touchCount > 0) dpi *= touchThreshMultiplier;

            evSys.pixelDragThreshold = Mathf.RoundToInt(dpi * inchesDragThreshold);
        }
        else
        {
            Debug.LogWarning("PhysicalDragThreshold component should be on an object with EventSystem", gameObject);
        }
    }
}

You could remove the touch-related stuff to avoid having code that runs every frame, but I couldn’t find any threshold that “felt right” for mouse and touch input simultaneously.

3 Likes