Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

OnDrop is not called if something else takes the OnPointerClick event?

Discussion in 'UGUI & TextMesh Pro' started by DESTRUKTORR, Sep 12, 2014.

  1. DESTRUKTORR

    DESTRUKTORR

    Joined:
    Jul 4, 2012
    Posts:
    22
    I've found that OnBeginDrag, OnDrag, and OnEndDrag are all called like normal, in this situation, but OnDrop is ignored.

    So far, I've only tested it with the OnPointerClick event in a separate monobehaviour on the same GameObject (which had an Image component attached to it, to catch the events).

    This seems like a bug, since I wouldn't expect two, different events to override each other. If anything, this would only make sense if both events relied on the same basal event (like OnRelease), but even then, it's a bit perplexing why they override each other, since the criteria for calling them don't overlap. If OnPointerClick succeeds, it means you didn't drag the pointer far enough to start a drag event. If OnDrop succeeds, it means you moved your pointer far enough to start a drag event, which is too far for OnPointerClick to succeed from.
     
    Railon23 likes this.
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Code (CSharp):
    1. if (!event.used)
    2. {
    3.     event.Use();
    4.    ...
    5. }
     
  3. DESTRUKTORR

    DESTRUKTORR

    Joined:
    Jul 4, 2012
    Posts:
    22
    What does that have to do with anything? I'm not trying to make it so that the event gets used up... I'm suggesting that the event should not be used up, if the failed event tests first (which I really have little to no control over).
     
    Last edited: Sep 14, 2014
    SmilingRob likes this.
  4. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    22
    Did you find a solution for this? I've the same problem right now. Thanks.
     
    BlackyPootis likes this.
  5. Yukichu

    Yukichu

    Joined:
    Apr 2, 2013
    Posts:
    420
    It's been a bit since I did my drag'n'drop inventory, but if I recall... something that implemented the Drag interfaces could not implement the Drop interfaces. They simply could not coexist on the same monobehavior.

    It sort of makes sense. OnEndDrag is basically OnDrop in theory. So separating them in my mind made sense. You drag an object, and the container you drop it into uses drop to determine if something is being dropped into it.
     
    Ziplock9000 likes this.
  6. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    22
    Right, I also got it working that way. I followed this video and extended my logic:

    The canvasGroup.blocksRaycasts is important to know, so that the dragged object doesn't get the hits (raycast). Then another object with an OnDrop handler can be hit.

    Code (JavaScript):
    1. function OnBeginDrag(eventData : PointerEventData) {
    2.     // some code
    3.     canvasGroup.blocksRaycasts = false;
    4. }
    5.  
    6. function OnEndDrag(eventData : PointerEventData) {
    7.     // some code
    8.     canvasGroup.blocksRaycasts = true
    9. }
     
    VaporAnomaly, abel86, voncarp and 4 others like this.
  7. jERRYN35

    jERRYN35

    Joined:
    Oct 30, 2016
    Posts:
    2
    I got it working by disabling EventTrigger when it suited me, and then enabling it afterwards.
     
  8. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    113
    haha like anyone stumbles over the same issues. Just make sure you disable Raycast for those Elements that shouldn't react to onDrop. In my case it was the Image of the Panel that had Raycast enabled.

    Now it's working like a charm.

    Edit:

    You may also consider using Canvas Groups, which helps to block raycast out for certain components.
     
    Last edited: Jun 12, 2019
    IsmaelRH1807 likes this.
  9. VaporAnomaly

    VaporAnomaly

    Joined:
    Jun 9, 2015
    Posts:
    18
    Thank you.
    This seems to be working for me.
     
unityunity