Search Unity

Detect button click was cancelled

Discussion in 'UI Toolkit' started by dccoo, May 23, 2019.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    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:
    33
    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:
    161
    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.