- Home /
Unity 4.6 scrollbar defaults to wrong position with grid layout
I have a gallery of items dynamically populated at run-time time with Unity 4.6's amazing GUI tools. It uses a scroll rect to handle overflow and a grid layout component. The problem is whenever I add a new item to the gallery, it moves the scrollbar to the center instead of the top. There must be a simple way to make new items not force scroll to the center and instead act like a W3C box model gallery you commonly see on the internet.
Answer by Ash-Blue · Dec 09, 2014 at 12:04 PM
For now I've created a scrollbar manager script that can be used to enforce a new scroll position on demand. Hopefully there is a more natural solution to this, but maybe not.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace Menu {
public class ScrollbarManager : MonoBehaviour {
Scrollbar scrollH;
Scrollbar scrollV;
void Awake () {
ScrollRect rect = GetComponent<ScrollRect>();
scrollH = rect.horizontalScrollbar;
scrollV = rect.verticalScrollbar;
}
void Start () {
ForceScroll(1f);
}
public void ForceScroll (float pos) {
if (scrollH) scrollH.value = pos;
if (scrollV) scrollV.value = pos;
}
}
}
The correct answer is to set the ScrollRect pivot y = 1. $$anonymous$$y above answer is now just good for carpel tunnel.
Your answer
Follow this Question
Related Questions
Create Dynamic buttons with info and update in new Unity 4.6 UI 1 Answer
UI 4.6: custom anchors breaking sizeDelta 0 Answers
Unity 4.6 ui restrict eventSystem only to keyboard input 3 Answers
How to achieve this desired render order with the new 4.6 UI? 2 Answers
UI layout got messed up after transferring project files! 1 Answer