Skip to content

ScrollView

Scrollable container with inertia, elastic bounds, and optional scrollbar handles. Automatically manages a content child that can be a Column, Row, or manual layout.

Inspector Setup

  1. Add AutoLayout to a container GameObject.
  2. Add AutoLayout Scroll View to the same GameObject.
  3. Content child is created automatically. Children added to the scroll view are reparented to the content container.
  4. Optionally assign scrollbar handle RectTransforms.
FieldTypeDefaultDescription
Scroll Sensitivityfloat20Mouse wheel multiplier
Scroll Wheel Axisint10 = horizontal, 1 = vertical
Enable InertiabooltrueMomentum after drag
Enable Elastic BoundsbooltrueBounce at edges
Deceleration Ratefloat0.135Inertia decay (0.01-0.5)
Elasticity Durationfloat0.3Bounce duration
Snap EnabledboolfalseEnable snap-to-interval after scroll ends
Snap Intervalfloat0Snap interval in pixels (0 = viewport size = page snap)
Snap AlignmentScrollSnapAlignmentStartStart or Center alignment within interval
Snap Speedfloat400Snap animation duration in ms
Vertical Scrollbar HandleRectTransform-Optional vertical scrollbar thumb
Horizontal Scrollbar HandleRectTransform-Optional horizontal scrollbar thumb

Code Usage

AutoUI Builder

// Vertical scroll view (Column content)
AutoUI.Create()
.WidthFill().HeightFill()
.ScrollViewVertical()
.Children(
AutoUI.Create().WidthFill().Height(100).Background(Color.red),
AutoUI.Create().WidthFill().Height(100).Background(Color.green),
AutoUI.Create().WidthFill().Height(100).Background(Color.blue)
// ... many children
)
.Build();
// Horizontal scroll view
AutoUI.Create()
.WidthFill().Height(200)
.ScrollViewHorizontal()
.Children(
AutoUI.Create().Width(200).HeightFill().Background(Color.red),
AutoUI.Create().Width(200).HeightFill().Background(Color.green)
)
.Build();

AutoUI.ScrollView() (static) is also available as a shortcut for AutoUI.Create().ScrollViewVertical().

Configuring ScrollView

AutoUI.Create()
.WidthFill().HeightFill()
.ScrollView(sv =>
{
sv.ScrollSensitivity = 30f;
sv.EnableInertia = true;
sv.EnableElasticBounds = true;
sv.DecelerationRate = 0.1f;
})
.Children(/* ... */)
.Build();

Page Snap

AutoUI.Create()
.WidthFill().HeightFill()
.ScrollView(sv =>
{
sv.SnapEnabled = true;
// SnapInterval = 0 means page snap (viewport size)
})
.Children(
AutoUI.Create().WidthFill().HeightFill().Background(Color.red),
AutoUI.Create().WidthFill().HeightFill().Background(Color.green),
AutoUI.Create().WidthFill().HeightFill().Background(Color.blue)
)
.Build();
// Custom interval snap (every 100px)
AutoUI.Create()
.WidthFill().HeightFill()
.ScrollView(sv =>
{
sv.SnapEnabled = true;
sv.SnapInterval = 100f;
sv.SnapAlignment = ScrollSnapAlignment.Center;
sv.SnapSpeed = 300f;
})
.Children(/* ... */)
.Build();

Programmatic Scrolling

var scrollView = go.GetComponent<AutoLayoutScrollView>();
// Scroll to position
scrollView.ScrollTo(new Vector2(0, 500), animated: true);
scrollView.ScrollTo(500f, animated: true); // Single axis
// Scroll by delta
scrollView.ScrollBy(new Vector2(0, 100));
// Scroll to child
scrollView.ScrollToChild(childTransform, animated: true);
// Stop scrolling
scrollView.StopScrolling();
// Refresh content size after adding/removing children
scrollView.RefreshContentSize();

Methods

MethodDescription
ScrollTo(Vector2 position, bool animated = true)Scroll to absolute position
ScrollTo(float position, bool animated = true)Scroll single axis
ScrollBy(Vector2 delta)Scroll by relative delta
ScrollBy(float delta)Scroll single axis by delta
ScrollToChild(Transform child, bool animated = true)Scroll to make child visible
RefreshContentSize()Recalculate content dimensions
StopScrolling()Stop inertia/animation
ExcludeFromReparenting(Transform child)Prevent child from being reparented to content

Properties

PropertyTypeDescription
ContentRectTransformAuto-managed content container
ContentModeScrollContentModeColumn, Row, or Manual
ScrollOffsetVector2Current 2D scroll offset
IsScrollingboolScroll in progress
IsDraggingboolUser is dragging
CanScrollHorizontalboolContent wider than viewport
CanScrollVerticalboolContent taller than viewport
ScrollSensitivityfloatMouse wheel multiplier
EnableInertiaboolMomentum after drag
EnableElasticBoundsboolEdge bounce
DecelerationRatefloatInertia decay rate
ElasticityDurationfloatBounce animation duration
PhysicsScrollPhysicsPhysics simulation instance
SnapEnabledboolSnap-to-interval enabled
SnapIntervalfloatSnap interval (0 = page)
SnapAlignmentScrollSnapAlignmentStart or Center
SnapSpeedfloatSnap duration in ms
IsSnappingboolSnap animation in progress
ControllerScrollControllerHeadless controller

Content Modes

ModeDescription
ColumnContent arranged vertically (default for vertical scroll)
RowContent arranged horizontally (default for horizontal scroll)
ManualCustom content layout

Notes

  • Children added to the scroll view are automatically reparented to the content container.
  • Use ExcludeFromReparenting() for children that should stay as direct children (e.g., scrollbar overlays).
  • The scroll view integrates with IUGUILayoutDependent to refresh content size after layout.
  • Implements IScrollHandler, IBeginDragHandler, IDragHandler, IEndDragHandler.
  • Scrollbar handles auto-resize based on content-to-viewport ratio.