ScrollView is not adjusting size of ViewPort/Content

  • Add a ScrollView to a canvas
  • Resize the height so that you can see all of the client area
  • Add a button inside the Viewport/Content element
  • Add another button under it, and scroll it down so that it disappears just off the bottom, out of sight
  • Run the app

Expected: I should be able to scroll the scroll view to see the lower button

Actual: I am able to pull the view so that the lower button is visible, but when I release the mouse button it snaps back so the button is not visible

Even if I add a ContentSizeFitter script to the Viewport/Content and try the different “Vertical Fit” settings I am unable to place the buttons where I specified and have it possible to scroll the button into view and keep it there.

Can someone tell me, is this a bug or am I doing something wrong?

(Unity 2017.3.0f3)

If I understood your question correctly, you want a chunk of space between the 2 buttons?

I was able to achieve something like that, using an empty game object in between the 2 buttons, as well as a vertical layout group on the content portion + a content size fitter.

I also used some layout elements on the 2 buttons and the empty game object.

I’m not 100% confident which part(s) made it work, but perhaps you can experiment with something like that, if that’s what you were asking :slight_smile:

2 Likes

Adding ContentSizeFitter to the Content object (with VerticalFit = PreferredSize) and then adding a VerticalLayoutGroup script as well fixed the problem. It allowed me to put a large empty Panel between the two buttons.

Thanks!

3 Likes

Cool :slight_smile: You’re welcome. Glad I could help.

1 Like