IPointerClickHandler does not fire if IPointerDownHandler is also implemented

As per title if both IPointerClickHandler and IPointerDownHandler are implemented then IPointerClickHandler does not fire.

Not that it should matter but I want to implement changing some object colors for MouseDown (pressed state) and then OnClick (active state) and want to use a click handler since IPointerUpHandler requires the mouse to be released over the object. If the implementation of IPointerDownHandler is empty then IPointerClickHandler does fire.

The documentation says nothing about this so I assume its a bug or is it like javascript and I need to return a bool to ensure propagation of the event?

Implementing one of the handlers makes the difference, you don’t usually need to do anything special inside the handlers. What are you doing in your IPointerDownHandler implementation? If it works with an empty handler then I suspect something you’re doing is disrupting event handling.

Note that the exact behaviour depends on what input module you use, e.g. InputSystemUIInputModule has slightly different behaviour than the built-in input modules.

And you can run into weird intricacies that you can often only resolve through debugging or experimentation. E.g. in the InputSystemUIInputModule, a IPointerDownHandler on a parent will prevent IPointerClickHandler handlers on children, unless they also have a IPointerDownHandler. I only figured that out by stepping through the code and checking what is happening*.

(*A click requires press and release target game objects to match. An IPointerDownHandler will take precedence over the IPointerClickHandler to set the event’s pointerPress target. This means that on release, the pointerPress will never match the click handler’s game object and a click cannot trigger. Adding an empty IPointerDownHandler with the IPointerClickHandler fixes this, as it will set the pointerPress to the right target on down.)

2 Likes

Thanks Adrian, You’re right I have run into these weird intricacies masked by a timing bug in my own code.