OnDrag methods not being called on Android in Unity 2018.3.5f1

I had the following kind of UI based player’s controller code for an Android phone, and in Unity 2017.4.18f1 it worked as expected. In Unity 2018.3.5f1, none of the OnDrag methods get called, while OnPointer* methods do get called. Inside the editor in Windows using a mouse pointer to simulate touch controls, all of them still get called. Is this a bug in Unity 2018? Need help…

public class VrJoypedAxis : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerUpHandler, IPointerDownHandler
{
    ...

    void Start()
    {
        ...
    }

    public void OnBeginDrag(PointerEventData ped)
    {
        ...
    }
    
    public void OnDrag(PointerEventData ped)
    {
        ...
    }

    public void OnEndDrag(PointerEventData ped)
    {
        ...
    }
    
    public void OnPointerDown(PointerEventData ped)
    {
    }

    public void OnPointerUp(PointerEventData ped)
    {
        ...
    }
}

UPDATE:

I tried alternative way, so this time I used “Event Trigger” component on an UI image object, with three events, pointer up, pointer down and drag. Alternative script looks like this::

public class VrJoypedAxis : MonoBehaviour
{
    public void Dragging() //Attached to Event Trigger component -> Drag
    {
        ...
    }

    public void ClickDown() //Attached to Event Trigger component -> Pointer Down
    {
        ...
    }

    public void ClickUp() //Attached to Event Trigger component -> Pointer Up
    {
        ...
    }
}

And it doesn’t work in exactly the same way as code above. With mouse cursor in Unity editor, all events work in both Unity 2017 and Unity 2018. On android device using touch input, in Unity 2017 all events also work but in Unity 2018, only pointer up and pointer down events work, while drag is dead.

As it looks to me, drag events are completely busted for touch input in Unity 2018.3.5f1.

Finally found the problem.

Cursor.lockState = CursorLockMode.Locked;

As of Unity 2018/2019, this command is disabling OnDrag events for touchscreen input when using Unity UI system. It might be doing the same not just in case of UI.

Don’t know if it is a bug or intentional fix in Unity 2018/2019 (make somewhat sense that it is intentional), but once I remove this command, drag is working fine once again.

I was struggling with the same problem on iOS. Try setting the Max Ray Intersections to zero on your Physics Raycaster. I can’t test on Android but hopefully this will work for you also. Apparently there is bug with the Physics Raycaster. See the post below.

Unity Event Trigger iOS

Cursor.lockState = CursorLockMode.Locked;

this didnt solve my problem
and i couldnt find anything that show me a way to use IDragHandler in android
i couldnt use EventTrigger cus i needed the dragging distance

actually i realized that i dont need dragging for what i need in my game
but this might solve your problem if you are struggling with this issue like me

public class AttackButtonCameraMove : EventTrigger
{
    [SerializeField] private FixedTouchField _touchField;

    private void Awake()
    {
        _touchField = FindObjectOfType<FixedTouchField>();
    }


    public override void OnPointerDown(PointerEventData data) {
        _touchField.attackPuttonPressed = true;
        _touchField.PointerOld = data.pressPosition;
        _touchField.Pressed = true;
    }

    public override void OnPointerUp(PointerEventData data)
    {
        _touchField.Pressed = false;
        _touchField.attackPuttonPressed = false;
    }
}

you can simply override OnDrag as well and it will work on android