The scroll bar works perfectly for awhile. Then after about 24 hours or so, these errors pop up in the console on start up of the project, usually after my computer has been off for the night. See image for errors. The scroll bar handle vanishes, the same 4 red errors appear in the console and the values for Top/Bottom of the scroll bar handle become NaN.
The settings for the scroll rect are in the picture.
I’m having the same problem. I tried to reproduce it for a bug report, but it’s not easy to reproduce.
The problem must however be a combination of deserialization/update order and some attributes in ScrollRect becoming zero, as there are potential divisions by zero such as / m_ContentBounds.size.y.
And m_ContentBounds.size can be set to zero in multiple ways in
ln 445 ff:
private void UpdateBounds()
{
m_ViewBounds = new Bounds(viewRect.rect.center, viewRect.rect.size);
m_ContentBounds = GetBounds(); // if (m_Content == null) return new Bounds(); thus size==zero
Vector3 contentSize = m_ContentBounds.size;
..
if (excess.x > 0)
{
..
contentSize.x = m_ViewBounds.size.x; // set to zero if m_ViewBounds.size.x is zero or not yet initialized
}
if (excess.y > 0)
{
contentSize.y = m_ViewBounds.size.y; // set to zero if m_ViewBounds.size.x is zero or not yet initialized
}
m_ContentBounds.size = contentSize;
..
}
The issue is as reported in the tracker here:
But although I’m using the latest Unity Version 4.6.1f1 and tried creating new scrollbars multiple times, it still produces the error.
Cool, i’m glad i’m not the only one running into this bug.
I have noticed that the bug only happens if unity opens the scene that contains the scroll bars on start-up. If i close unity with a scene that does not contain the scroll bars, i do not run into the errors.
Also having this highly annoying issue. I have found that I only need to replace the handle object with a properly configured new UI image object to get the scrollbar working again. (Albeit temporarily, as it soon breaks again.)
Guys, I’m having this same problem and I just notice something. Are you using Content Size Fitter? I was. I simply deactivated them and everything went back to normal. Really often I struggle with bugs generated by Content Size Fitter and Aspect Ratio Fitter.
my solution is kind of magic just put this script to component of handle
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Handle : MonoBehaviour {
// Use this for initialization
void Awake ()
{
Scrollbar scrollbar;
RectTransform rectTransform;
rectTransform = transform.GetComponent<RectTransform>();
scrollbar = transform.parent.transform.parent.GetComponent<Scrollbar>();
scrollbar.size = 0;
rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -10);
rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, 10);
scrollbar.size = 1;
rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -10);
rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, 10);
}
}
The problem was for me that the ScrollBar size property would fail and be NaN when I stopped the Game mode. Indeed my content panel (in the ScrollRect script) has a VerticalLayoutGroup component attached, this is what is causing the problem.
Since the NaN value appears after the game is stopped, it will propagate to the Handle Top and Bottom value when started again.
The thing we needed to do then, is to reset the ScrollBar size property before starting the game again. I modified your script and it works fine for me now:
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class ScrollBarFix : MonoBehaviour {
void Update()
{
Fix();
}
void OnGUI()
{
Fix();
}
void OnRenderObject()
{
Fix();
}
private void Fix()
{
if (!Application.isPlaying)
{
Scrollbar scrollbar;
RectTransform rectTransform;
rectTransform = transform.GetComponent<RectTransform>();
scrollbar = transform.parent.transform.parent.GetComponent<Scrollbar>();
scrollbar.size = 0;
rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, 2);
rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, -2);
scrollbar.size = 1;
rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, 2);
rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, -2);
}
}
}
Unfortunately, both code examples were not able to fix the already broken Scrollbars, so I had to write my own code. My code will execute on Awake once (I think this is performant enough). In the editor you can execute it by clicking on the Fix button in the Inspector (no need to execute it again and again since it breaks again and again…). So I click “Fix” if I edit exactly this scrollbar, otherwise I just leave it broken, so that it is fixed on start up. Also, I have provided some Inspector properties for the size of the scrollbars…
uMyGUI_ScrollbarHandleUnityFix.cs
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Fix for a nasty Unity bug:
/// Unity Forum: http://forum.unity3d.com/threads/vertical-scroll-bar-handle-top-bottom-becomes-nan-with-scroll-view.285490/
/// Unity Issue Tracker: http://issuetracker.unity3d.com/issues/m-transforminfo-dot-localaabb-dot-isvalid-when-reimporting-the-example-project
/// </summary>
public class uMyGUI_ScrollbarHandleUnityFix : MonoBehaviour
{
[SerializeField]
private Vector2 m_anchorMin = new Vector2(0.8f, 0f);
[SerializeField]
private Vector2 m_anchorMax = new Vector2(1f, 1f);
[SerializeField]
private Vector2 m_pivot = new Vector2(0.5f, 0.5f);
[SerializeField]
private Vector2 m_offsetMin = new Vector2(-10f, -10f);
[SerializeField]
private Vector2 m_offsetMax = new Vector2(10f, 10f);
public void Awake()
{
RectTransform rectTransform = GetComponent<RectTransform>();
// needed to set anchoredPosition3D if not executed anchoredPosition3D will not be changed due to NaN
rectTransform.localPosition = Vector3.zero;
// remove NaN values
rectTransform.anchoredPosition3D = Vector3.zero;
// reset broken values to default
rectTransform.anchorMin = m_anchorMin;
rectTransform.anchorMax = m_anchorMax;
rectTransform.pivot = m_pivot;
rectTransform.offsetMin = m_offsetMin;
rectTransform.offsetMax = m_offsetMax;
}
}
uMyGUI_ScrollbarHandleUnityFixInspector.cs MUST BE IN EDITOR FOLDER!
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.Collections;
/// <summary>
/// Fix for a nasty Unity bug:
/// Unity Forum: http://forum.unity3d.com/threads/vertical-scroll-bar-handle-top-bottom-becomes-nan-with-scroll-view.285490/
/// Unity Issue Tracker: http://issuetracker.unity3d.com/issues/m-transforminfo-dot-localaabb-dot-isvalid-when-reimporting-the-example-project
/// </summary>
///
[CustomEditor(typeof(uMyGUI_ScrollbarHandleUnityFix))]
public class uMyGUI_ScrollbarHandleUnityFixInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("FIX")) { ((uMyGUI_ScrollbarHandleUnityFix)target).Awake(); }
}
}
#endif
This indeed works, thank you. I’m just using the runtime script (first one) without the Editor script. I also noticed that the broken scrollbars extend all over the canvas (not visibly, but with regards to the events triggered, you can check this via the UI EventSystem. So this had in my case the effect that
I have the same problem. I’m using 4.6.2 in WebPlayer and under scrollbar the handle’s RectTransform Top and Bottom is NaN and i cannot change them back to zero(was right at first). My solution is to duplicate a new one and delete the old one and it works for now. i also noticed that input.getmousebutton cannot work with this “handle problem” that’s why i found it.