Hi,
Using Unity 2021.2.3, I wonder why PointerDownEvent or MouseDownEvent are not called on buttons upon a mouse click or SendEvent. Is it a bug? MouseDownEvent do is called on a VisualElement upon a SendEvent with PointerDownEvent. I’d expect it to work on a button as well. ClickEvent act as mouse/pointer up, but I need the down callback.
The Button indeed deals with ClickEvents, via its clickable manipulator. In order to be able to get the PointerDownEvents you need to register in TrickeDown mode:
var button = ...; // or var button = root.Q<Button>(className: "someButton"), etc.
button.RegisterCallback<PointerDownEvent>(
e => {
Debug.Log("Button pointer down!");
},
TrickleDown.TrickleDown);
Wish I’d figure this by myself. This is a weird design in my opinion to specify “down” twice. Why are we even allowed to register a callback with down and up at the same time which does nothing? Perhaps a warning could be printed in the log? It works, let’s move on, thanks.
Hi,
First of all, glad it fixes your problem.
Second, I understand your point – unfortunately it’s just that the Button element is a special snowflake and was written a while ago. Clickable is just a shortcut for the more simple cases and that, in retrospect, would probably not be our approach today. But that said, the clickable callback you are referring to should be doing something, unless you did not specify a callback when creating the Button instance.
This trick does not work for me in 2023.1
button.RegisterCallback(HandleClicked, TrickleDown.TrickleDown); does not work
button.RegisterCallback(HandleClicked) works
This took me a while to figure out. I need to learn more about event propagation . Adding the trickle down flagged worked for me but I still have to clue why. All of my buttons are on the same layer as far as I know