- Home /
EventTrigger steals OnDrop but not OnDrag
I have written my own component, which implements IBeginDragHandler, IDragHandler and IDropHandler. I want to add an EventTrigger component that comes with UnityEngine.UI, but when I add it I stop getting calls to OnDrop on my component. OnBeginDrag and OnDrag are called as usual.
My component code:
public class MyComponent : MonoBehaviour, IBeginDragHandler, IDragHandler, IDropHandler
{
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("OnBeginDrag!");
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("OnDrag!");
}
public void OnDrop(PointerEventData eventData)
{
Debug.Log("OnDrop!");
}
}
When I start my scene with a Game object with this component attached, the expected log output is:
OnBeginDrag!
OnDrag!
...
OnDrag!
OnDrop!
This is the case as long as I only have default components and my component. But if I add an Event -> Event Trigger component (without even specifying anything in it) to the same GameObject and run again, the output is:
OnBeginDrag!
OnDrag!
...
OnDrag!
The OnDrop is never called. The order of the components doesn't affect anything.
Is there a way to stop EventTrigger from using up the OnDrop call?
You could extend the EvenTrigger class to only implement the events you want to intercept.
Example script here: https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
Add Canvas Group to the Selected Object. By default, the SelectedObject would by the object from where drag has started(Only if there is a Button Component on that GameObject). You can assign some other object in OnDragStart
Like
eventData.selectedObject = m_DraggingIcon;
Answer by iDeally · Oct 11, 2017 at 08:48 AM
You should have receiver with IOnDropHandler at drop point. If you dont, OnEndDrag is called instead of OnDrop
Your answer
![](https://koobas.hobune.stream/wayback/20220612105008im_/https://answers.unity.com/themes/thub/images/avi.jpg)