Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Make scrolling move faster in scrollRect?

Discussion in 'UGUI & TextMesh Pro' started by Bitfabrikken, Dec 19, 2015.

  1. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    Currently when you scroll something in a scrollRect, by using the mouse, touch etc., it's on a 1:1 basis.
    Move the mouse 100 pixels, and the content is scrolled 100 pixels.

    Is there a way to e.g. double this?
    So when moving the mouse (or dragging when using touch) 100 pixels, the content is scrolled 200 pixels.
    I guess I'm looking for a multiplier or something, but I don't know where to find it, or how to achieve it.
    Hope someone can help me :)
     
  2. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Isn't there a sensitivity in the scrollview prefab? Have you tried playing with that?
     
  3. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    There is, but it's got to do with sensitivity towards the start of scrolling, not scrolling speed itself.
     
  4. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Pretty sure scrolling speed is based on the User's Scroll wheel setup via the machine's system settings.
     
  5. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    And on mobile? I want to be able to increase scroll speed on mobile, when touch-dragging to scroll.
     
  6. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Mobile is based on momentum, how quick the user flicks their finger.
     
  7. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    I'm pretty sure it's not. It seems to be 1:1 when I make something with scrollRect. Both in editor and live on devices.
     
  8. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    You could look into this.
     
  9. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Pretty sure it is.
     
  10. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    As I said above, scrollSensitivity has to do with sensitivity towards the start of scrolling, not scrolling speed itself. The manual is poorly worded.
     
  11. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    There is a deceleration. Try decreasing that?
     
  12. Bitfabrikken

    Bitfabrikken

    Joined:
    Mar 24, 2013
    Posts:
    34
    Again it's scrolling speed when scrolling I'm after (when touching and scrolling) - not deceleration, which occurs after you've scrolled (released touch). There's no deceleration occuring when you're actively scrolling obviously.
     
  13. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    So, normally when you scroll with your finger the user is "dragging" the window in the direction they're moving their finger. It gives the illusion that they're physically dragging the object. I implemented my own drag feature quite easily but my first iteration had the speed too high. Every pixel I moved my finger the object underneath moved 2. It was a really, really awkward feeling.

    Basically, I don't think you want what you're asking for. Every app I've ever used, game or not, you just flicked the contents up really fast and let is scroll for a long time if you wanted to scroll quickly. Reduce the deceleration time so people can flick, call it good. :) No one will think, "Golly I wish this was faster" except you, most likely.
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Sorry to necro-post this thread, but I made a quick patch to the Unity ScrollRect to get faster-than-finger scrolling. It is AWESOME on mobile.

    It is EXTREMELY useful when you have large images of content, and yet you want to quickly go through them without having to whip them along "ballistically."

    (This link updated 6:36 AM 3/13/2021, along with the line numbers below)

    If you go to this file:

    https://github.com/Unity-Technologies/uGUI/blob/2019.1/UnityEngine.UI/UI/Core/ScrollRect.cs

    (This file is also available from the Unity Package Manager.)

    Then you can download ScrollRect.cs and modify it to make your own that supports higher-than-finger scroll rates. Once you use it, every other scroll rate with 1:1 finger mapping (i.e., normal Apple / Android scroll rates) just feels glacially slow.

    I recommend renaming the class and filename, such as "MyScrollRect.cs" and of course the internal MonoBehavior itself.

    The first patch is about line 104 in the property declarations, add these two lines:

    Code (csharp):
    1. [SerializeField]
    2. private float m_ScrollFactor = 1.0f;
    3. public float scrollFactor { get { return m_ScrollFactor; } set { m_ScrollFactor = value; } }
    4.  
    The second patch is inside the OnDrag() method, approximately line 763 in the original file, AFTER the pointerDelta is calculated, but before it is used to calculate position:

    Code (csharp):
    1. var pointerDelta = localCursor - m_PointerStartLocalCursor;
    2. pointerDelta *= m_ScrollFactor;    // this line is new!
    3. Vector2 position = m_ContentStartPosition + pointerDelta;
    Now you're done. Use this newly-named ScrollRect anywhere you would use the Unity one and you can have faster-than-finger (or faster-than-mouse drag) scrolling. It's awesome if I do say so myself!
     
    Last edited: Mar 13, 2021
  15. Trungdv

    Trungdv

    Joined:
    Dec 1, 2012
    Posts:
    22
    @Kurt-Dekker Thank you very much! You saved my day, sir!
     
    Kurt-Dekker likes this.
  16. ostatnicky

    ostatnicky

    Joined:
    Jan 23, 2017
    Posts:
    1
    Kurt-Dekker likes this.
  17. kidzooly

    kidzooly

    Joined:
    Jan 23, 2016
    Posts:
    26
    Kurt-Dekker likes this.
  18. vuthang

    vuthang

    Joined:
    Mar 7, 2017
    Posts:
    50

    Attached Files:

    Kurt-Dekker likes this.
  19. SkylinR

    SkylinR

    Joined:
    Sep 4, 2015
    Posts:
    6
    Kurt-Dekker likes this.
  20. YuHeLong

    YuHeLong

    Joined:
    Apr 17, 2015
    Posts:
    15
    After I put in the modified script in my assets folder, How do I add the script to the gameobject, it says script not found?
     
  21. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Make sure it a) compiles without any errors, b) is named uniquely, and c) has the same exact filename as the class name, including capitalization.
     
  22. KarolRG

    KarolRG

    Joined:
    Jul 9, 2019
    Posts:
    2
    I've created also some scripts which improve speed of scrolling but in a little bit different way. Previous ones was making faster entire dragging and inertia scrolling. I wanted only that inertia to be faster (moment when you stop dragging screen and it's scrolling by "force" after swipe).
    It's simple to Use:
    - Add ScrollRectFasterEditor.cs to "Assets/Editor". If you don't have this catalogue then create one.
    - Add ScrollRectFaster.cs anywhere in your Asset folder.
    - Create ScrollView GameObject
    - Change ScrollRect script to ScrollRectFaster script (just delete old one and drag on GO to add new script)
    - Finally drag all required things to ScrollRectFaster like Content, Viewport etc.
    And that's all.

    To increase speed of scrolling edit value Inertia Velocity Multiplier (Like on screenshot)

    Important: As i wrote it's working with inertia so checkbox Inertia needs to be checked to display that option to increase scroll speed.
     

    Attached Files:

    Last edited: Jun 9, 2020
  23. carlosmartinezsandoval

    carlosmartinezsandoval

    Joined:
    May 24, 2020
    Posts:
    1
    @Kurt-Dekker, thanks, your solution works straightforward.
     
    Kurt-Dekker likes this.
  24. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Same here, thanks KaroLRG !

    Suddenly we can have a really fast and smooth scrollview in Unity ! It is incredible Uity did not fixed/improved their solution till 2015 !
     
    Kurt-Dekker and SkylinR like this.
  25. NKCSS

    NKCSS

    Joined:
    Aug 29, 2015
    Posts:
    19
    I set scroll sensitivity to 50 and it works great (my items are 50px high, so scrolls 1 item on each wheel click)

    I looked at the current source, but it's pretty clear that this is exactly what you want to have: https://bitbucket.org/Unity-Technol...nityEngine.UI/UI/Core/ScrollRect.cs#lines-648

    The only myster to me, is why Unity just doesn't set this to anything between 30 and 200 themselves by default, but hey, you can change it easily :)
     
  26. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    I imagine the behavior of this constant is dependent on the Canvas' RenderMode as well as the CanvasScaler's UIScaleMode. Perhaps Unity chose a value that works for the default settings and you've since changed those?
     
  27. unityPashok

    unityPashok

    Joined:
    Sep 1, 2020
    Posts:
    7
    Hello. Can you send me please these files for scrollbar, I have no access on BitBucket. And where I need to put them into the project?
     
  28. unityPashok

    unityPashok

    Joined:
    Sep 1, 2020
    Posts:
    7
    Thank you. I did it. This is awesome
     
  29. unity_wCJkYF0CzcRmLw

    unity_wCJkYF0CzcRmLw

    Joined:
    Mar 20, 2020
    Posts:
    1
    Thank you. This is really awesome.
     
    Kurt-Dekker likes this.
  30. thientv84

    thientv84

    Joined:
    Mar 2, 2013
    Posts:
    4
    Kurt-Dekker likes this.
  31. munkiki7

    munkiki7

    Joined:
    Jul 10, 2018
    Posts:
    3
    Thanks, Kurt :)
     
    Kurt-Dekker likes this.
  32. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    Hi everybody!
    Thanks for scripts and here is my gem to our collection.
    If you want to scroll feel more natural just comment lerp part in inertia block
    upload_2022-9-21_22-17-12.png
     
    zhuchun likes this.
  33. NGS_MEGA

    NGS_MEGA

    Joined:
    Jun 12, 2023
    Posts:
    1
    I'm late to the party. But wanted to share what helped me here.
    First off, thanks @KarolRG for the scripts! They're magic.
    Seems like the scroll UI behavior is little more complex in nature - two different swipes getting registered (longer scroll, shorter scroll). More like a MagLev behavior and I think the longer scroll works with existing Unity's ScrollRect script while the shorter scroll seems to be tricky. Also, the Lerp was more jagged with 'Application.targetFrameRate' on mobile has a default other than '60'.

    These configs worked for me along with scripts shared by KarolRG:
    1. Define 'Application.targetFrameRate = 60;' in one of main scripts 'Start()'
    2. Attached config after trial and error
     

    Attached Files:

  34. imerwise

    imerwise

    Joined:
    May 20, 2023
    Posts:
    1
    Was looking for a way to improve ScrollRect, and I just found this topics and the script which is a gem. Working perfectly :)
    Great job @Kurt-Dekker. Thx for the work!
     
    Kurt-Dekker likes this.
  35. marcozakaria

    marcozakaria

    Joined:
    Sep 17, 2017
    Posts:
    23
    Thanks works great on mobile