Hello everyone,
I’m writing here before submitting a bug to make sure that it’s a bug and not my misunderstanding on handlers flow.
I’ve simplified it to simples mode, two UI Images. One has script DropMe.cs (that’s the big square we drop onto), second is DragMe.cs (that’s the draggable one).
When we drag DragMe to DropMe, DropMe uses OnPointerEnter and OnPointerExit to do some logic - in this case, change background color. OnDrop there’s another logic, in this case print log message.
DragMe has logic OnPointerDown to unblock CanvasGroup, OnDrag to move around and OnPointerUp to block CanvasGroup and to print log message to show touch is up.
Now, the bug!
Everything works as expected (change bg color, notice OnDrop, unchange colors) except tiny area around border, I’m guessing 1 or 2 px, where we are already OnPointerEnter but OnDrop never registers. It’s very hard to spot at the beginning, so I’ve attached two videos (in gif format :x) , normal behaviour and wrong behaviour, where in second you can see that I already got OnPointerUp from DragMe but there’s never OnDrop printed.
Do I miss something or it’s a bug and I can file bugreport?
I’m posting all two scripts used to make those amazing gifs.
If anyone has similar problem, my current solution is global script that checks if there are any objects that are “dragged” and touch.count is 0, then I force them to undrag :x
DragMe:
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler {
public void OnPointerDown( PointerEventData eventData ) {
GetComponent<CanvasGroup>().blocksRaycasts = false;
transform.position = eventData.position;
}
public void OnBeginDrag (PointerEventData eventData) {}
public void OnDrag (PointerEventData eventData) {
transform.position = eventData.position;
}
public void OnEndDrag (PointerEventData eventData) {}
public void OnPointerUp( PointerEventData eventData ) {
Debug.Log ("! OnPointerUp");
GetComponent<CanvasGroup>().blocksRaycasts = true;
}
public void OnPointerExit( PointerEventData eventData ) {
}
}
DropMe:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class DropMe : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler {
Image bg;
static Color C1 = new Color (20f / 255f, 180f / 255f, 190f / 255f, 150f / 255f);
static Color C2 = new Color (0f / 255f, 0f / 255f, 0f / 255f, 100f / 255f);
void Awake() {
bg = GetComponent<Image> ();
}
public void OnPointerEnter(PointerEventData data)
{
if (data.pointerDrag == null) return;
Debug.LogFormat ("Enter {0}",data.pointerDrag.name);
bg.color = C1;
}
public void OnDrop(PointerEventData data)
{
Debug.LogWarningFormat ("Drop {0}", data.pointerDrag.name);
if (data.pointerDrag == null) return;
bg.color = C2;
}
public void OnPointerExit(PointerEventData data)
{
if (data.pointerDrag == null) return;
Debug.LogFormat ("Exit {0}", data.pointerDrag.name);
bg.color = C2;
}
}

