ScrollView displays its content inside a scrollable area. When you add content to a ScrollView, the content is added to the content container (#unity-content-container
) of the ScrollView.
You can specify the direction of the scroll bar movement, whether the horizontal or vertical scroll bars are visible, and control the speed of the scroll bars.
To set the direction of the scroll bar movement in UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary Builder, in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary window of the ScrollView, select one of the following options for Mode:
To set the visibility of the scroll bar in UI Builder, in the Inspector window of the ScrollView, select one of the following options for Horizontal Scroller Visibility or Vertical Scroller Visibility:
To control the scroll speed of the ScrollView, override the USS built-in variable --unity-metrics-single_line-height
. The default value is 18px
. For example:
:root {
--unity-metrics-single_line-height: 500px;
}
Important: When you use CloneTree()
without parameter or Instantiate()
, it adds a TemplateContainer
that stops the line height from propagating. Use CloneTree(root)
instead.
You can wrap visual elementsA node of a visual tree that instantiates or derives from the C# VisualElement
class. You can style the look, define the behaviour, and display it on screen as part of the UI. More info
See in Glossary inside a ScrollView so that the elements display in a row. If the row is full, the elements continue to display on the next line.
To wrap visual elements inside a ScrollView, set the ScrollView’s content container flex direction to Row and flex wrap to Wrap.
In USS:
.unity-scroll-view__content-container {
flex-direction: row;
flex-wrap: wrap;
}
In C#:
scrollview.contentContainer.style.flexDirection = FlexDirection.Row;
scrollview.contentContainer.style.flexWrap = Wrap.Wrap;
To wrap the text of an element inside a ScrollView, for example, the text of a Label element, do the following:
white-space: normal;
to the Label element in USS, UXML, or C#.
C# class: ScrollView
Namespace: UnityEngine.UIElements
Base class: VisualElement
This element has the following member attributes:
Name | Type | Description |
---|---|---|
elasticity |
float |
The amount of elasticity to use when a user tries to scroll past the boundaries of the scroll view. Elasticity is only used when touchScrollBehavior is set to Elastic. |
horizontal-page-size |
float |
This property controls the speed of the horizontal scrolling when using a keyboard or the on-screen scrollbar buttons (arrows and handle), based on the size of the page. |
horizontal-scroller-visibility |
UIElements.ScrollerVisibility |
Specifies whether the horizontal scroll bar is visible. |
mode |
UIElements.ScrollViewMode |
Controls how the ScrollView allows the user to scroll the contents. ScrollViewMode The default is ScrollViewMode.Vertical . Writing to this property modifies the class list of the ScrollView according to the specified value of ScrollViewMode . When the value changes, the class list matching the old value is removed and the class list matching the new value is added. |
mouse-wheel-scroll-size |
float |
This property controls the scrolling speed only when using a mouse scroll wheel, based on the size of the page. It takes precedence over the –unity-metrics-single_line-height USS variable. |
nested-interaction-kind |
UIElements.ScrollView+NestedInteractionKind |
The behavior to use when scrolling reaches limits of a nested ScrollView . |
scroll-deceleration-rate |
float |
Controls the rate at which the scrolling movement slows after a user scrolls using a touch interaction. The deceleration rate is the speed reduction per second. A value of 0.5 halves the speed each second. A value of 0 stops the scrolling immediately. |
vertical-page-size |
float |
This property controls the speed of the vertical scrolling when using a keyboard or the on-screen scrollbar buttons (arrows and handle), based on the size of the page. |
vertical-scroller-visibility |
UIElements.ScrollerVisibility |
Specifies whether the vertical scroll bar is visible. |
This element inherits the following attributes from its base class:
Name | Type | Description |
---|---|---|
focusable |
boolean |
True if the element can be focused. |
tabindex |
int |
An integer used to sort focusables in the focus ring. Must be greater than or equal to zero. |
This element also inherits the following attributes from VisualElement
:
Name | Type | Description |
---|---|---|
content-container |
string |
Child elements are added to it, usually this is the same as the element itself. |
name |
string |
The name of this VisualElement. Use this property to write USS selectors that target a specific element. The standard practice is to give an element a unique name. |
picking-mode |
UIElements.PickingMode |
Determines if this element can be pick during mouseEvents or IPanel.Pick queries. |
style |
string |
Reference to the style object of this element. Contains data computed from USS files or inline styles written to this object in C#. |
tooltip |
string |
Text to display inside an information box after the user hovers the element for a small amount of time. This is only supported in the Editor UI. |
usage-hints |
UIElements.UsageHints |
A combination of hint values that specify high-level intended usage patterns for the VisualElement . This property can only be set when the VisualElement is not yet part of a Panel . Once part of a Panel , this property becomes effectively read-only, and attempts to change it will throw an exception. The specification of proper UsageHints drives the system to make better decisions on how to process or accelerate certain operations based on the anticipated usage pattern. Note that those hints do not affect behavioral or visual results, but only affect the overall performance of the panel and the elements within. It’s advised to always consider specifying the proper UsageHints , but keep in mind that some UsageHints might be internally ignored under certain conditions (e.g. due to hardware limitations on the target platform). |
view-data-key |
string |
Used for view data persistence (ie. tree expanded states, scroll position, zoom level). This is the key used to save/load the view data from the view data store. Not setting this key will disable persistence for this VisualElement . |
The following table lists all the C# public property names and their related USS selector.
C# property | USS selector | Description |
---|---|---|
ussClassName |
.unity-scroll-view |
USS class name of elements of this type. |
viewportUssClassName |
.unity-scroll-view__content-viewport |
USS class name of viewport elements in elements of this type. |
horizontalVariantViewportUssClassName |
.unity-scroll-view__content-viewport--horizontal |
USS class name that’s added when the Viewport is in horizontal mode. ScrollViewMode.Horizontal
|
verticalVariantViewportUssClassName |
.unity-scroll-view__content-viewport--vertical |
USS class name that’s added when the Viewport is in vertical mode. ScrollViewMode.Vertical
|
verticalHorizontalVariantViewportUssClassName |
.unity-scroll-view__content-viewport--vertical-horizontal |
USS class name that’s added when the Viewport is in both horizontal and vertical mode. ScrollViewMode.VerticalAndHorizontal
|
contentAndVerticalScrollUssClassName |
.unity-scroll-view__content-and-vertical-scroll-container |
USS class name of content elements in elements of this type. |
contentUssClassName |
.unity-scroll-view__content-container |
USS class name of content elements in elements of this type. |
horizontalVariantContentUssClassName |
.unity-scroll-view__content-container--horizontal |
USS class name that’s added when the ContentContainer is in horizontal mode. ScrollViewMode.Horizontal
|
verticalVariantContentUssClassName |
.unity-scroll-view__content-container--vertical |
USS class name that’s added when the ContentContainer is in vertical mode. ScrollViewMode.Vertical
|
verticalHorizontalVariantContentUssClassName |
.unity-scroll-view__content-container--vertical-horizontal |
USS class name that’s added when the ContentContainer is in both horizontal and vertical mode. ScrollViewMode.VerticalAndHorizontal
|
hScrollerUssClassName |
.unity-scroll-view__horizontal-scroller |
USS class name of horizontal scrollers in elements of this type. |
vScrollerUssClassName |
.unity-scroll-view__vertical-scroller |
USS class name of vertical scrollers in elements of this type. |
horizontalVariantUssClassName |
.unity-scroll-view--horizontal |
USS class name that’s added when the ScrollView is in horizontal mode. ScrollViewMode.Horizontal
|
verticalVariantUssClassName |
.unity-scroll-view--vertical |
USS class name that’s added when the ScrollView is in vertical mode. ScrollViewMode.Vertical
|
verticalHorizontalVariantUssClassName |
.unity-scroll-view--vertical-horizontal |
USS class name that’s added when the ScrollView is in both horizontal and vertical mode. ScrollViewMode.VerticalAndHorizontal
|
scrollVariantUssClassName |
.unity-scroll-view--scroll |
|
disabledUssClassName |
.unity-disabled |
USS class name of local disabled elements. |
You can also use the Matching Selectors section in the Inspector or the UI Toolkit Debugger to see which USS selectors affect the components of the VisualElement
at every level of its hierarchy.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.