I am trying to register a click event on a label. PointerUpEvent works, but ClickEvent doesn’t work, and that is the one I need. I don’t want to use a button. Is this possible or is it a bug?
label.RegisterCallback<ClickEvent>(evt => OnClickAnimationButton(animationType, label));
Cheers!
Hi!
This code should work, I tried it with a simple setup, so I would say there’s probably some other control eating your mouse/pointer events.
Another way to do it would be to use the Clickable manipulator like so:
label.AddManipulator(new Clickable(evt => Debug.Log("Clicked")));
But both should work. I would try to find what is the target of that ClickEvent at the moment. You could always use the TickleDown parameter in the RegisterCallback method to get the event before the other control.
1 Like
I changed it from a label to a button and the click event works now using .clicked +=. What is the difference between the label and the button’s click event that allows the button to work but not the label? I didn’t change anything besides making it a button.
Cheers!
Button uses the Clickable manipulator. It does a few more things than just listening to pointer events, it also captures the pointer. Maybe that is what was missing. Because otherwise it is not that different from a label, Button is basically a TextElement with different styling.
It must have been the scrollview behind it then! Good to know for me and anyone else looking for this.