Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Detect button click was cancelled

Discussion in 'UIElements' started by dccoo, May 23, 2019.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    127
    I have a panel that can be dragged. It contains an Event Trigger, so when I stop dragging, it goes back to the original position (by calling a function in the event Pointer Up).

    Inside this panel I have a button. When I try to drag the panel by holding the button and moving, it drags ok, but when I release the buttom, the panel doesn't come back to original position.

    How can I solve this? If the Button component had an "On Cancel" event, it would be nice.
     
  2. pierre_10

    pierre_10

    Unity Technologies

    Joined:
    Apr 1, 2016
    Posts:
    2
    is it possible the event is not triggered because your mouse is on top of the button? As a quick hack i would call the same event on the button.
     
    dccoo likes this.
  3. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    127
    Yes. This is, however, strange. When I hold the button, the panel's Event Trigger detects the "Pointer Down" event and calls the corresponding function, but when I release the button, it doesn't catch the "Pointer Up" event.
    I was able to solve by removing the Button component from the button object. Instead I added another Event Trigger on it.