What could prevent a scrollbar from receiving a mouseUp event?
The problem
I have several scroll views in my current project. If I use the scrollbar and release the mouse button while moving the mouse, the scroll view keeps moving with the mouse. It seems the scrollbar does not register the mouseUp event. This does not happen with "grabbing" the scroll rect to move it.
During normal usage this happens quite often. It also often leads to a situation where you scroll down to a button you want to click, but when you move the mouse pointer towards the button it scrolls away from it. I guess you can see how that can be very annoying.
My attempts
I did not manage to reproduce this in a new project. Unfortunately the original project belongs to my company, so I can not post it here.
There are very few MonoBehaviours which implement UI listeners like IDragHandler etc. and I already tried deactivating those, but that did not fix it.
It does not happen if I use the Touch Input Module instead of the Standalone Input Module, however then I am unable to use the scrollwheel.
It also didn't help to call these as a workaround:
PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
scrollRect.OnEndDrag(pointerEventData);
scrollRect.StopMovement();
scrollbar.OnPointerUp(pointerEventData);
scrollbar.OnDeselect(pointerEventData);
The question
What could prevent a scrollbar from receiving a mouseUp event? Alternatively, how can I manually send a mouseUp event to a scrollbar?
Answer by TheQuestioner · May 26, 2017 at 03:35 PM
I managed to stop the undesirable scrollbar movement by setting the "interactable" property of the scrollbar to false and then true again.
Here is the code I ended up with:
public void Update()
{
if (!Input.GetMouseButtonUp(0)) return;
Scrollbar[] scrollbars = FindObjectsOfType<Scrollbar>();
foreach (Scrollbar scrollbar in scrollbars)
{
scrollbar.interactable = false;
scrollbar.interactable = true;
}
}