Search Issue Tracker
Won't Fix
Votes
0
Found in
2021.3.47f1
2022.3.54f1
6000.0.31f1
6000.1.0a8
6000.2.0a1
Issue ID
UUM-90904
Regression
No
Scrollbar scroll value returns to a predetermined value and makes scrolling with a Mouse hardly possible when 2 or more Number of Steps is set
How to reproduce:
1. Open the “IN-90487-Scroll Bar.zip“ project
2. Open the “SampleScene“
3. Select the “Scrollbar Vertical“ GameObject to the right of the “Journal“ in the Scene view
4. Change the “Number Of Steps“ field to any number except 0 in the Scrollbar Component in the Inspector
5. Enter Play Mode
6. Scroll in the Scroll view with the Mouse scroll wheel on a low speed
7. Observe the “Value“ field in the Inspector
Expected result: Value is not set to a predetermined value, making “stepped“ scrolling dysfunctional
Actual result: Value changes insignificantly and returns to a predetermined value
Reproducible in: 2021.3.47f1, 2022.3.54f1, 6000.0.31f1, 6000.1.0a8
Reproduced on: Windows 11 Pro (23H2)
Not reproduced on: No other environment tested
Notes:
- Scrolling by dragging works as expected
- If the number of steps is set to 2, scrolling with the Mouse is practically impossible as the delta on the scroll would not be enough to jump 0.5 units of value in one frame because the value snaps to either 0 or 1
- The ability to scroll depends on the size of the Content GameObject Rect
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- DownloadHandlerScript.CompleteContent is called twice when building for WebGL
- Scene view has Y coordinates of the Screen Position node flipped when some of the URP features are disabled
- Volumetric fog shader variants are missing from build when "Strict Shader Variant Matching" is disabled
- Unnecessary modifications clutter the Scene when using a RectTransform driven by a LayoutGroup in a Prefab
- Files in the target folder are deleted without a proper warning when building an iOS project
Resolution Note:
Thank you for bringing this issue to our attention. While it's possible to use the Scrollbar's stepping feature with the Scroll Rect, this specific interaction is not well supported by the design and fixing bugs for that scenario would risk bringing unforeseen consequences.
However, we are providing you with a script that can be used as a potential workaround for this specific scenario. It does not handle any other scenario than vertical scrolling with a mouse. It is provided as a starting point and should be tested in your specific game.
The proposed solution is to detect when a scroll event is being ignored by the Scrollbar's stepping behaviour, that is when the Scroll Rect position is rounded down or up to the closest valid step, and apply the sufficient delta for the scroll to happen in the expected direction. This script is a replacement for the ScrollRect component (you can replace an existing instance by enabling the Debug mode of the Inspector and editing the Script property of the Scroll Rect and replace it with this one).
```
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class SteppedScrollRect : ScrollRect
{
public override void OnScroll(PointerEventData data)
{
// We're only interested in situations where we have a Vertical Scrollbar with stepping
if (verticalScrollbar == null && verticalScrollbar.numberOfSteps <= 1)
return;
// Save the current position before the scroll event is processed by the ScrollRect
float savePosition = verticalNormalizedPosition;
base.OnScroll(data);
// The scroll event has now processed the Scroll Rect, reflected in its verticalNormalizedPosition
// This value has not yet been affected by the Scrollbar's step behaviour
// Since they only sync their values during the next LateUpdate()
float diff = savePosition - verticalNormalizedPosition;
// Skip scroll events that didn't actually move the Scroll Rect at all
if (Mathf.Approximately(0.0f, diff))
return;
// This is the size between each step of the Scrollbar between 0 and 1
float stepSize = 1f / (verticalScrollbar.numberOfSteps - 1);
// A scroll delta (relative to content size) that is less than half the stepSize will result in an "ignored" scroll
// Hence we will attempt to patch it by moving to the next valid step value in the expected direction
if (Mathf.Abs(diff) < stepSize * 0.5f)
{
// Make sure to add 0.01f in order to put the value above or below the required step
float minDistanceToScroll = stepSize * 0.5f + 0.01f;
// Finally, overwrite the ScrollRect position by applying the minimumScrollDistance in the right direction
verticalNormalizedPosition = savePosition - Mathf.Sign(diff) * minDistanceToScroll;
}
}
}
```
We appreciate your input and understanding. Please let us know if you have any other concerns or issues you would like to report in the future.