Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question ListView mousewheel scrolling speed

Discussion in 'UI Toolkit' started by rimisaby, Sep 8, 2021.

  1. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    In my application, ListViews (UIToolkit runtime 2021.2.0b10) scroll extremely slowly with the mousewheel. I'm not finding a way how to adjust the speed of the scrolling.

    According to the documentation, ScrollViews have the "VerticalPageSize" attribute that is supposed to control exactly that, but this parameter is not available in ListViews.

    Nevertheless, even changing VerticalPageSize in ScrollViews doesn't have any effect on the scrolling speed either.

    Am I missing something, or is it "a work in progress"-topic?
     
    CunningFox146 likes this.
  2. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    365
    What value do you use? Mine is set to 1000.
     
  3. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    For ScrollView, it doesn't matter, what I set, it doesn't have any impact (I just tried 1000 - no difference).

    In ListView I don't have any value to set.
     
  4. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    323
    It seems to work with 2021.2.0b6 so it must be a recent regression. I reported the case (#1364827) and will post the link to it when it becomes available (will take a few days).
     
  5. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    I guess you mean here the VerticalPageSize parameter of the ScrollView. That is one issue. Thanks for filing a bug report.

    The other issue is the slow scrolling of ListViews. Can you please confirm that I'm not missing something when I don't find a way to change the scroll speed of ListViews?
     
  6. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    323
    I investigated with the team and here's the answer I got:

    We’ve had a regression on scrolling recently caused by changes to page size, and basically realized that scrolling should not depend on page size. It should always scroll the same amount regardless of the size of the viewport/content. So now we depend on line height. Users can override --unity-metrics-single_line-height in uss on their ScrollView/ListView to change the sensitivity. Default is 18px.​

    Also, in the future we'll make single line height adjustable from the code as well.
     
  7. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    Thank you for this information. Redeclaring the USS variable --unity-metrics-single_line-height in my custom stylesheet did the trick:

    :root {
    --unity-metrics-single_line-height: 500px;
    }

    In my case, 500px give a natural scrolling experience. One scroll step moves about one line of the list at 30px item height.
     
    craftsmanbeck likes this.
  8. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    365
    Since updateing to The beta we have the same bug.

    But on 2021.2.0b15 the workaround seams not to change anything.
    No matter what value I set --unity-metrics-single_line-height to, the scroll-speed does not change.
     
    CunningFox146 likes this.
  9. herkip

    herkip

    Joined:
    Dec 21, 2013
    Posts:
    30
    Hi, I am having a similar issue can't sense scrolling speed. Is there any more new information? I am using 2021.2.0f1
     
  10. SkywardRoy

    SkywardRoy

    Joined:
    Jan 14, 2017
    Posts:
    22
    I managed to make it work with a custom callback!
    Code (CSharp):
    1. [SerializeField] private UIDocument uiDocument;
    2.  
    3. private float scrollVelocity;
    4. private float scrollDamping = 0.1f;
    5. private Scroller verticalScroller;
    6.  
    7. private void Start () {
    8.     var rootElement = uiDocument.rootVisualElement
    9.     var list = rootElement.Q<ListView>("List");
    10.  
    11.     verticalScroller = list.Q("unity-content-and-vertical-scroll-container").Q<Scroller>();
    12.  
    13.     list.RegisterCallback<WheelEvent>(@event => {
    14.         scrollVelocity += @event.delta.y * 100;
    15.  
    16.         // Stop the event here so the builtin scroll functionality of the list doesn't activate
    17.         @event.StopPropagation();
    18.     });
    19. }
    20.  
    21. private void Update () {
    22.     if (verticalScroller != null) {
    23.         verticalScroller.value += scrollVelocity;
    24.         scrollVelocity -= scrollVelocity * scrollDamping;
    25.     }
    26. }
     
    sharkbitgamesdev and herkip like this.
  11. mrSaig

    mrSaig

    Joined:
    Jan 14, 2010
    Posts:
    68
    Any updates here?
    It is a real pain :/

    :root {
    --unity-metrics-single_line-height: 500px;
    }

    does not work for me either :(
     
  12. StefanSigl

    StefanSigl

    Joined:
    Oct 29, 2019
    Posts:
    4
    In Unity 2021.2.10f1 I still have trouble setting scrollspeed with ScrollView and ListViews its always veeeery slow :(
     
    Protagonist likes this.
  13. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Also having this problem. Changing --unity-metrics-single_line-height does nothing. Why is there no communication on this?
     
    StefanSigl likes this.
  14. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    Setting --unity-metrics-single_line-height used to work with 2021.2.0b10 but as others reported, it stopped working with later versions. With 2021.2.11f1 still no luck.
     
  15. rimisaby

    rimisaby

    Joined:
    Nov 21, 2016
    Posts:
    14
    Found the problem.

    Before 2021.2.0b15 it used to be enough to set the key --unity-metrics-single_line-height on the root visual element. In later Unity versions, the key must be applied to the parent of the root visual item, which is in my case (runtime) the Panel Settings (check it in the Toolkit Debugger).

    I didn't find a way to do this in the UI Builder directly, so I add my stylesheet also to the parent per script on startup:
    Code (CSharp):
    1. StyleSheet styleSheet = Resources.Load<StyleSheet>("UI/UI-Main");
    2.             if (styleSheet != null)
    3.                 root.parent.styleSheets.Add(styleSheet);
    where root is uiDocument.rootVisualElement.

    Now, :root {
    --unity-metrics-single_line-height: 500px;
    } in the stylesheet is applied correctly.

    The scrolling is fast again. :)
     
    StefanSigl, ChGuidi and JasonBricco like this.
  16. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Yes, this does appear to work. Thanks!
     
  17. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    754
    @AlexandreT-unity

    This seems to not work in the latest beta 9. I reported the bug. Is there any insight into what is going on? Case #: 1403738
     
  18. StefanSigl

    StefanSigl

    Joined:
    Oct 29, 2019
    Posts:
    4

    You are my HERO! Thanks this works!
     
  19. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    234
    2021.2.7f1 here and this doesn't work for us (using rootVisualElement or rootVisualElement.parent of runtime UI Document). Our setup has two UI Documents if that makes any difference. Would really appreciate some input from the team on how to make this usable - I had hoped it would be fixed by now - it's an incredibly painful issue.
     
  20. MousePods

    MousePods

    Joined:
    Jul 19, 2012
    Posts:
    754
    https://issuetracker.unity3d.com/is...scroll-view-scrolling-when-entering-play-mode
     
  21. Issus94

    Issus94

    Joined:
    Nov 22, 2021
    Posts:
    6
    How do i add:

    :root {
    --unity-metrics-single_line-height: 500px;
    }

    into my Project? My Style Sheet from UI Toolkit is named UserInterface. Do i just go into the uss and add the Line at the top? Also i added at ProjectStart the Line:

    StyleSheet styleSheet = Resources.Load<StyleSheet>("UI/UserInterface");
    if (styleSheet != null)
    root.parent.styleSheets.Add(styleSheet)

    But nothing is changing when i integrate both into my Project.
     
    CunningFox146 likes this.
  22. wechat_os_Qy00uAsb2nct0nigJU5z6tzQs

    wechat_os_Qy00uAsb2nct0nigJU5z6tzQs

    Joined:
    Dec 9, 2021
    Posts:
    1
    The same problem has been tested in 2021.3 and 2021.2.16, and still cannot be modified
     
    Issus94 and CunningFox146 like this.
  23. leanon00

    leanon00

    Joined:
    Apr 4, 2020
    Posts:
    2
    Simple workaround:

    Code (CSharp):
    1. private ScrollView m_TargetScrollView;
    2.  
    3. public float ScrollFactor { get; set; } = 100;
    4.  
    5. private void RegisterCallback()
    6. {
    7. m_TargetScrollView.RegisterCallback<WheelEvent>((evt) =>
    8. {
    9.     TargetScrollView.scrollOffset = new Vector2(0, TargetScrollView.scrollOffset.y + ScrollFactor * evt.delta.y);
    10. }
    11. evt.StopPropagation();
    12. }
     
    nh92, svencan, Issus94 and 1 other person like this.
  24. AyadLivv

    AyadLivv

    Joined:
    Feb 17, 2022
    Posts:
    1
    Works Perfectly Thanks !
     
  25. StripeGuy

    StripeGuy

    Joined:
    Dec 30, 2016
    Posts:
    52

    For anyone wondering how to do this, his code is confusing and wrong (or I don't understand the way he did it).

    Declare a variable:
    Code (CSharp):
    1. private ScrollView m_TargetScrollView;
    Then in Start(), link it to your element in UIBuilder:
    Code (CSharp):
    1. m_TargetScrollView = rootUI.Q<ScrollView>("My-ScrollView-Name-example");
    Then register a callback to it in start() as well, like so:
    Code (CSharp):
    1. m_TargetScrollView.RegisterCallback<WheelEvent>((evt) =>
    2.         {
    3.             m_TargetScrollView.scrollOffset = new Vector2(0, m_TargetScrollView.scrollOffset.y + ScrollFactor * evt.delta.y);
    4.             evt.StopPropagation();
    5.         }
    6.  );
     
  26. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    765
    ANTONBORODA likes this.
  27. ANTONBORODA

    ANTONBORODA

    Joined:
    Nov 16, 2017
    Posts:
    46
    This seems to be different for ScrollView and ListView containers.
    For scroll view you can actually use both WheelEvent and --unity-metrics-single_line-height workaround.
    For ListView nothing seems to work and you are stuck to whatever is "hardcoded".
     
  28. niekdw96

    niekdw96

    Joined:
    Feb 11, 2020
    Posts:
    3
    Incorrect, this is the fix I am currently using for ListView scrolling:

    Code (CSharp):
    1.    
    2.     public static void FixListViewScrollingBug(ListView listView) {
    3.         #if UNITY_EDITOR
    4.             var scroller = listView.Q<Scroller>();
    5.             listView.RegisterCallback<WheelEvent>(@event => {
    6.                 scroller.value +=  @event.delta.y * 100;
    7.                 @event.StopPropagation();
    8.             });
    9.         #else
    10.             var scroller = listView.Q<Scroller>();
    11.             listView.RegisterCallback<WheelEvent>(@event => {
    12.                 scroller.value -=  @event.delta.y * 10000;
    13.                 @event.StopPropagation();
    14.             });
    15.         #endif
    16.     }
    17.  
    It seems like the behavior is different In the build vs the editor. Just noticed actually that the behavior is also different on a windows build compared to a linux build. So I will be adding a third section for that case rofl
     
  29. ANTONBORODA

    ANTONBORODA

    Joined:
    Nov 16, 2017
    Posts:
    46
    This is so broken I can't believe it...
    But thanks for the solution.
     
    Last edited: Oct 17, 2022
  30. franklx2

    franklx2

    Joined:
    Jul 18, 2016
    Posts:
    3
    Allow me to echo my frustration with this defect along with the rest of you. This has been very user unfriendly. That being said, I understand the position Unity is in. It is incredibly difficult to ship features and keep everyone happy without breaking stride. We are fortunate that the community is filled with talented individuals like yourselves to supply solutions and workarounds. I have tried every suggestion in here, and the above is the one that worked for me. Happy Coding.
     
    StripeGuy likes this.
  31. conor_saber

    conor_saber

    Joined:
    Oct 14, 2022
    Posts:
    3
    I was able to change the scroll speed using StripeGuy's fix above.
    Note this issue first appeared for me only after I added an EventSystem because I needed to use a legacy Canvas-based UI in the project as well as UIElements. With the EventSystem disabled, scroll speed is normal. When the EventSystem is enabled, I need to use the scroll view multiplier code above to get decent scroll speeds.
    Using Unity 2021.3.5f1.
     
    StripeGuy likes this.
  32. vejab

    vejab

    Joined:
    Dec 21, 2021
    Posts:
    85
    Maybe your issue is fixed if you use 2021.3.22f1 instead.
    https://issuetracker.unity3d.com/is...rolling-when-entering-play-mode-and-in-builds
     
  33. SeanBannister

    SeanBannister

    Joined:
    Jul 13, 2020
    Posts:
    21
    Just to confirm what @conor_saber mentioned, I had an EventSystem I didn't need to use in this project, on disabling the EventSystem the scroll speed is fine.
     
    CameronLewis likes this.