Hi all,
i have implemented the IDropHandler interface with the onDrop() function.
I’m making an inventory using Drag and Drop elements.
My Project works fine within the Unity IDE.
However, when I build my app on the Android device, the onDrop() function is never called. Everything else works just fine.
I have no clue where to start to fix this.
Does anybody have a suggestion?
Best Regards
Axel
1 Like
I have tried several days to find a solution. However I have not started an entire new project to check for this problems root.
I was not able to find a solution so far.
However if somebody encounters this problem. Here is a workaround:
Use the OnEndDrag function on your dragging object and Tag the object that shall take the Drop.
Instead of the OnDrop function define your own function (OnDropRaycast) and pass your gameObject.
public void OnEndDrag(PointerEventData eventData)
{
if (eventData != null)
{
PointerEventData pointerData = new PointerEventData(EventSystem.current) { pointerId = -1, };
pointerData.position = eventData.position;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
foreach (RaycastResult result in results)
{
if (result.gameObject.tag.Equals("MyTag"))
{
result.gameObject.GetComponent<MergeSpotScript>().OnDropRaycast(this.gameObject);
}
}
}
....
}
Best regards.
5 Likes
Hello, thank you so much for posting your workaround, it worked perfectly! I blasted my brains on this issue for the past 4 hours and I think the issue is actually a bug in the StandaloneInputModule of the EventSystem.
The problem doesn’t only happen when you build but also when you use unity remote. So this got me thinking that there could be an issue with the touch controls of the input module.
I’m new to coding but I compared the touch code with the click code;
In the click code:
private void ReleaseMouse(PointerEventData pointerEvent, GameObject currentOverGo)
{
ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
var pointerClickHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
// PointerClick and Drop events
if (pointerEvent.pointerClick == pointerClickHandler && pointerEvent.eligibleForClick)
{
ExecuteEvents.Execute(pointerEvent.pointerClick, pointerEvent, ExecuteEvents.pointerClickHandler);
}
if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
{
ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
}
where as in the touch code:
if (released)
{
// Debug.Log("Executing pressup on: " + pointer.pointerPress);
ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler);
// Debug.Log("KeyCode: " + pointer.eventData.keyCode);
// see if we mouse up on the same element that we clicked on...
var pointerClickHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
// PointerClick and Drop events
if (pointerEvent.pointerClick == pointerClickHandler && pointerEvent.eligibleForClick)
{
ExecuteEvents.Execute(pointerEvent.pointerClick, pointerEvent, ExecuteEvents.pointerClickHandler);
}
else if (pointerEvent.pointerDrag != null && pointerEvent.dragging)
{
ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler);
}
I think the problem is the “else if” at the end which should be “if”. I maybe completely wrong but this is my best guess
You Saved My Life, Thank You ;)
if u don`t want to add tag, maybe just get component and check if exist.
Dropable droper = result.gameObject.GetComponent();
if (droper != null)
{
droper.OnDropRaycast(eventData);
}
Thank you so much for your solution. Did you create a bug report about it?