4.6 UI - how to make a dynamic scrollbar?

How do you make in new 4.6 UI a scrollbar to appear only when the content size is greater than the ScrollView size?

Various way’s to do this it’s up to you but not difficult to script.

If you’re scrollbar is likely to be dynamically then add a CanvasGroup and

if (myScrollbar.size == 1) { myScrollbar.GetComponent<CanvasGroup>().alpha = 0; myScrollbat.GetComponent<CanvasGroup>().interactable = false; myScrollbar.GetComponent<CanvasGroup>().blocksRaycast= false; }

Of course you can setActive as well or make that gameObject enabled = false so it’s up to you for the approach. And you’ll need an else to switch it on if not == 1.

The previous answer has the correct approach as far as I can tell. The reason for checking the scroll bar height, instead of the content rect against your scrollview rect, like you would naturally think to do has to deal with the order of execution in the RebuildLayout method, unless you aren’t using any autolayout componenents and are calculating it on your own.

I recommend however that instead of adding a canvas group component, unless you’d like to have a non interact-able but visible scrollbar, would just be to get the images of the scrollbar and handle and set their enable to false. This will accomplish the same thing without an extra component.