How can i temporarily disable all drag events for a GameObject?

I am using IBeginDragHandler (and IDragHandler etc.) on a MonoBehaviour that is attached to that GameObject.

Right now i do…

bool _dragEnabled;

public void OnBeginDrag(PointerEventData eventData)
{
  if (_dragEnabled)
  {
    //do something
  }
  else
  {
    eventData.pointerDrag = null;
  }
}

…but find it rather hackish. I’d like to disable all drag events, so that OnBeginDrag (and OnDrag etc.) does not get called.

Also a hack, but a bit simpler: set the event system’s pixel drag threshold to some big value:

FindObjectOfType<EventSystem>().pixelDragThreshold = int.MaxValue;
3 Likes