PointerDownEvent never fires for Button

Hello,

I’m trying to implement drag’n’drop functionality in runtime for a button. So, according to this , I need to register a VisualElement for mouse events to make it draggable. Since it’s in runtime for a game, I went for pointer events instead. Here’s what I do:

if (_draggable) {
            mainButton.RegisterCallback<PointerDownEvent>(PointerDown);
            mainButton.RegisterCallback<PointerMoveEvent>(PointerMove);
            mainButton.RegisterCallback<PointerUpEvent>(PointerUp);
        }

The problem: when I start trying to drag the button, I get PointerMove calls and PointerUp call when I release the mouse. But PointerDown never gets called.

Why? Is there a way to receive it?

Hi!
You can take a look at this post for an example of drag and drop that should work in the runtime.

For your use case, the Button class has a manipulator that will detect clicks on it, which is probably interfering with the events you are trying to use. It is easier to not use the manipulator (by setting it to null) and register a ClickEvent manually on it.

1 Like

Thank you for replying. Setting clickable on the button and then adding custom MouseManipulator did help.

1 Like