Hi, I’m adding a few events to my button. But sadly the PointerDownEvent is not firing The rest are working fine. I checked it in the events debugger and it should be fired.
public class InventoryElement : CustomButton
{
public InventoryElement()
{
RegisterCallback<PointerDownEvent>(OnPointerDownEvent);
RegisterCallback<PointerEnterEvent>(OnPointerEnterEvent);
RegisterCallback<PointerUpEvent>(OnPointerUpEvent);
RegisterCallback<PointerMoveEvent>(OnPointerMoveEvent);
}
}
Unity 2021.3.8
Probably not the same problem, in my case, it works perfectly fine on 2021.3 projects.
It only fails to work on build, not in editor.
I found that adding TrickleDown.TrickleDown makes this event to be called.
button.RegisterCallback<PointerDownEvent>(OnPointerDownEvent, TrickleDown.TrickleDown);
Indeed, buttons call StopImmediatePropagation() on the PointerDownEvent, so you can’t listen to that event during the BubbleUp phase because it has already been stopped. That’s only the case for PointerDownEvent, and only for Buttons, Toggles, and other controls using the Clickable manipulator.
It really is an implementation detail (not really documented, and subject to changing in future releases), it’s unfortunate that it shows up and interferes with your CustomButton logic. We are trying to minimize the number of such cases, and Clickable is one of the manipulators that’s on our radar for needing a bit of rework and simplification. That being said, I wouldn’t go as far as saying this is a bug per se, but it’s a detail that you need to know when coding logic for buttons right now, and be careful about. Your using TrickleDown is a good workaround, I’d say.
Also, the bugs referred to earlier were something else, the first one was buttons weren’t tracking the pointer movement properly, and the bug Gekigengar is having is a case of events missing for the entire project, not specific to buttons. In all cases, those are bugs that we’re going to fix or have fixed, but thank you for putting us on the spot for them!
2 Likes