Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question ScrollView: Scroll bars not active/hidden as expected

Discussion in 'UGUI & TextMesh Pro' started by SimRuJ, Jun 10, 2021.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    Hello everyone,

    I'm using Unity 2021.1.6f1 and just came across a problem:

    I added a ScrollView to a panel on my canvas. The content's height is set to 300 by default and both scroll bars use the "auto hide and expand viewport" setting by default. No matter if I add buttons to "Content" (or even a vertical layout group) or leave it empty, the vertical scroll bar is always active.
    If I set the content's height to anything smaller than the viewport (e.g. 100) or set it to stretch inside the viewport (with left=right=top=bottom=0), then the vertical scroll bar is hidden but scrolling also breaks completely and the vertical scroll is never enabled (even when the content is "full").

    The horizontal scroll bar is also affected in a different way: If I move an e.g. button further to one side, so it's cut off, the horizontal scroll bar is still always disabled.

    How do I fix these problems? Is the ScrollView bugged in this specific Unity version?
     
  2. DarthHawk13

    DarthHawk13

    Joined:
    Feb 24, 2016
    Posts:
    63
    I'm using 2019 and it still has serious issues. I've found a work around where I can use it but my workaround removes the scroll bars. This workaround does allow the end user to scroll through the options using the mouse scroll wheel. If Horizontal is enabled and not Vertical moving the mouse scroll wheel will move the window right/left instead of up/down. However, the end user can't see where the view port is in relation to the content being scrolled through. The scroll bars are supposed to provide that functionality. But as the scroll bars have never worked for me anyway removing them doesn't result in losing anything. I've included a screenshot of my Scroll View settings. I've set it to only scroll vertically as I don't want it to scroll horizontally for the project I'm working on.
    Workaround.PNG
     
    Last edited: Oct 28, 2021
  3. Lynxed

    Lynxed

    Joined:
    Dec 9, 2012
    Posts:
    121
    Still bugged and just does not work properly. It never hides scroll bars for me.
     
  4. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    I updated to 2021.1.24f1 and created a new ScrollView (UI -> ScrollView) and it worked fine for that one. I still had the old one in my scene and its scroll bar was still bugged in a weird way. I changed something and now both ScrollViews are working as expected: If it's not full, then the scroll bar is hidden and once the "Content" is overflowing, then the scroll bar is enabled.

    My setup (vertical list with buttons):
    ScrollViews' parents: Vertical Layout Group (controls children's height) + Content Size Fitter (2x Preferred Size)
    ScrollView: Layout Element (Preferred Height set)
    Viewport: No extra component
    Content: Vertical Layout Group (Control Child Size: Width + Child Force Expand: Width) + Content Size Fitter (Horizontal: Unconstrained, Vertical: Min Size)

    Not sure if that's the best setup but it works. The two really important things are the Layout Group and the Content Size Fitter (maybe that's what I added) because without them the scroll bar might show up but it won't work properly.

    @DarthHawk13
    Tbh, I'd upgrade to Unity 2021, if possible.

    @Lynxed
    Did you set them to autohide?
     
    mowax74 and CladCobra like this.
  5. RABL1N

    RABL1N

    Joined:
    Sep 18, 2022
    Posts:
    1
    add a content size fitter to the content section and set it to preferred size.
     
    andyz, GamerFawn and mauricioweber like this.