- Home /
Scrollbar Automatically Resizing on Play, Stays Resized in Editor
Hello! I am using Unity 2020.1 to create a text-based adventure, but my scrollbar component’s size keeps changing to 1 when I click play. I want to set the scrollbar size to be 0.2. When I end play the scrollbar remains resized to 1 even though changes made while in playmode shouldn’t affect editing mode.
This resizing issue only happens when I assign the scrollbar to a scroll rect. I have tried deleting and recreating the scroll rect. I have also tried taking the scroll rect and scrollbar outside of the canvas to see if it was an issue with the canvas. The scrollbar still resizes itself.
I have tried setting the value of the scrollbar to many different numbers but no matter what number I put it is resized to 1.
I have tried using this script to resize the scrollbar on awake and then I assign ChangeScrollPs() to the scrollbar to be cused OnValueChanged() for the scrollbar. This changes the size of the scrollbar but when I move the handle the text does not change position. It is also worth noting that this script does not change the size of the scrollbar if I put “scollbar.size = 0.2f” in Awake() instead of Update().
using UnityEngine;
using UnityEngine.UI;
public class ScrollbarFix : MonoBehaviour
{
public Scrollbar scrollbar;
public ScrollRect scrollRect;
// Use this for initialization
private void Update()
{
scrollbar.size = 0.2f;
scrollRect.horizontalNormalizedPosition = 0.4f;
}
public void ChangeScrollPos()
{
scrollRect.horizontalNormalizedPosition = scrollbar.value;
}
}
How can I make my scroll bar stay the size I set it to?
Here is a picture of the scrollbar component:
Here is a picture of the scroll rect component:
Here is a link to download the project to play with: https://github.com/Daniel-Nimitz/Text-Based-Adventure/tree/Scrollbar-resizing-issue