Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Vertical scroll bar handle top/bottom becomes NaN with scroll view.

Discussion in 'Unity UI & TextMesh Pro' started by yakm, Dec 13, 2014.

  1. yakm

    yakm

    Joined:
    Sep 12, 2014
    Posts:
    23
    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.
     
  2. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    151
    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
    Code (CSharp):
    1.  / m_ContentBounds.size.y
    .

    Code (CSharp):
    1.  
    2. ln 361: m_HorizontalScrollbar.size = Mathf.Clamp01((m_ViewBounds.size.x - Mathf.Abs(offset.x)) / m_ContentBounds.size.x);
    3. ln 367: m_VerticalScrollbar.size = Mathf.Clamp01((m_ViewBounds.size.y - Mathf.Abs(offset.y)) / m_ContentBounds.size.y);
    4.  
    And m_ContentBounds.size can be set to zero in multiple ways in
    Code (CSharp):
    1. ln 445 ff:
    2.   private void UpdateBounds()
    3.   {
    4.       m_ViewBounds = new Bounds(viewRect.rect.center, viewRect.rect.size);
    5.       m_ContentBounds = GetBounds(); // if (m_Content == null) return new Bounds(); thus size==zero
    6.  
    7.       Vector3 contentSize = m_ContentBounds.size;
    8.       ..
    9.       if (excess.x > 0)
    10.       {
    11.            ..
    12.            contentSize.x = m_ViewBounds.size.x; // set to zero if m_ViewBounds.size.x is zero or not yet initialized
    13.       }
    14.       if (excess.y > 0)
    15.       {
    16.           contentSize.y = m_ViewBounds.size.y; // set to zero if m_ViewBounds.size.x is zero or not yet initialized
    17.       }
    18.  
    19.       m_ContentBounds.size = contentSize;
    20.       ..
    21.   }
    22.  
    23.  
    The issue is as reported in the tracker here:
    http://issuetracker.unity3d.com/iss...-isvalid-when-reimporting-the-example-project
    But although I'm using the latest Unity Version 4.6.1f1 and tried creating new scrollbars multiple times, it still produces the error.
     
    Last edited: Jan 9, 2015
  3. yakm

    yakm

    Joined:
    Sep 12, 2014
    Posts:
    23
    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.
     
  4. DoobyFrucan

    DoobyFrucan

    Joined:
    Jan 22, 2014
    Posts:
    1
    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.)
     
  5. bestknighter

    bestknighter

    Joined:
    Dec 2, 2014
    Posts:
    7
    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.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
    Even if those are used, the scroll bar handles should not become invalid.

    I have tried to create a reproduction of this issue, but I failed to get a reliable one. Did anyone submit a bug report about this issue?
     
  7. bestknighter

    bestknighter

    Joined:
    Dec 2, 2014
    Posts:
    7
    Yes. Pixelcloud Games did. Here is the link: http://issuetracker.unity3d.com/issues/m-transforminfo-dot-localaabb-dot-isvalid-when-reimporting-the-example-project

    Yes, indeed. And my workaround actually doesn't work.
     
    Dantus likes this.
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,669
  9. Derek-Wong

    Derek-Wong

    Joined:
    Jan 5, 2015
    Posts:
    16
    4.6.2 is out but still having this issue...anybody have any workaround on this?
     
  10. tgyjcgyjcfj

    tgyjcgyjcfj

    Joined:
    Feb 27, 2015
    Posts:
    1
    my solution is kind of magic just put this script to component of handle

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Handle : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Awake ()
    9.     {
    10.         Scrollbar scrollbar;
    11.         RectTransform rectTransform;
    12.  
    13.         rectTransform = transform.GetComponent<RectTransform>();
    14.         scrollbar = transform.parent.transform.parent.GetComponent<Scrollbar>();
    15.         scrollbar.size = 0;
    16.  
    17.         rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -10);
    18.         rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, 10);
    19.  
    20.         scrollbar.size = 1;
    21.  
    22.         rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, -10);
    23.         rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, 10);
    24.     }
    25.  
    26. }
     
    FreebordMAD likes this.
  11. AnonHandler12

    AnonHandler12

    Joined:
    Nov 27, 2014
    Posts:
    1
    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:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. [ExecuteInEditMode]
    5. public class ScrollBarFix : MonoBehaviour {
    6.  
    7.     void Update()
    8.     {
    9.         Fix();
    10.     }
    11.     void OnGUI()
    12.     {
    13.         Fix();
    14.     }
    15.     void OnRenderObject()
    16.     {
    17.         Fix();
    18.     }
    19.  
    20.     private void Fix()
    21.     {
    22.         if (!Application.isPlaying)
    23.         {
    24.             Scrollbar scrollbar;
    25.             RectTransform rectTransform;
    26.  
    27.             rectTransform = transform.GetComponent<RectTransform>();
    28.             scrollbar = transform.parent.transform.parent.GetComponent<Scrollbar>();
    29.             scrollbar.size = 0;
    30.  
    31.             rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, 2);
    32.             rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, -2);
    33.  
    34.             scrollbar.size = 1;
    35.  
    36.             rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, 2);
    37.             rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, -2);
    38.         }
    39.     }
    40. }
    41.  
     
    FreebordMAD likes this.
  12. FreebordMAD

    FreebordMAD

    Joined:
    Mar 15, 2013
    Posts:
    358
    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
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. /// <summary>
    5. /// Fix for a nasty Unity bug:
    6. /// Unity Forum: http://forum.unity3d.com/threads/vertical-scroll-bar-handle-top-bottom-becomes-nan-with-scroll-view.285490/
    7. /// Unity Issue Tracker: http://issuetracker.unity3d.com/issues/m-transforminfo-dot-localaabb-dot-isvalid-when-reimporting-the-example-project
    8. /// </summary>
    9. public class uMyGUI_ScrollbarHandleUnityFix : MonoBehaviour
    10. {
    11.     [SerializeField]
    12.     private Vector2 m_anchorMin = new Vector2(0.8f, 0f);
    13.     [SerializeField]
    14.     private Vector2 m_anchorMax = new Vector2(1f, 1f);
    15.     [SerializeField]
    16.     private Vector2 m_pivot = new Vector2(0.5f, 0.5f);
    17.     [SerializeField]
    18.     private Vector2 m_offsetMin = new Vector2(-10f, -10f);
    19.     [SerializeField]
    20.     private Vector2 m_offsetMax = new Vector2(10f, 10f);
    21.    
    22.     public void Awake()
    23.     {
    24.         RectTransform rectTransform = GetComponent<RectTransform>();
    25.         // needed to set anchoredPosition3D if not executed anchoredPosition3D will not be changed due to NaN
    26.         rectTransform.localPosition = Vector3.zero;
    27.         // remove NaN values
    28.         rectTransform.anchoredPosition3D = Vector3.zero;
    29.         // reset broken values to default
    30.         rectTransform.anchorMin = m_anchorMin;
    31.         rectTransform.anchorMax = m_anchorMax;
    32.         rectTransform.pivot = m_pivot;
    33.         rectTransform.offsetMin = m_offsetMin;
    34.         rectTransform.offsetMax = m_offsetMax;
    35.     }
    36. }
    37.  
    uMyGUI_ScrollbarHandleUnityFixInspector.cs MUST BE IN EDITOR FOLDER!
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEngine.UI;
    5. using System.Collections;
    6.  
    7. /// <summary>
    8. /// Fix for a nasty Unity bug:
    9. /// Unity Forum: http://forum.unity3d.com/threads/vertical-scroll-bar-handle-top-bottom-becomes-nan-with-scroll-view.285490/
    10. /// Unity Issue Tracker: http://issuetracker.unity3d.com/issues/m-transforminfo-dot-localaabb-dot-isvalid-when-reimporting-the-example-project
    11. /// </summary>
    12. ///
    13. [CustomEditor(typeof(uMyGUI_ScrollbarHandleUnityFix))]
    14. public class uMyGUI_ScrollbarHandleUnityFixInspector : Editor
    15. {
    16.     public override void OnInspectorGUI()
    17.     {
    18.         base.OnInspectorGUI();
    19.         if (GUILayout.Button("FIX")) { ((uMyGUI_ScrollbarHandleUnityFix)target).Awake(); }
    20.     }
    21. }
    22. #endif
    23.  
     
  13. benni05

    benni05

    Joined:
    Mar 17, 2011
    Posts:
    58
    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

    Code (CSharp):
    1. EventSystem.current.IsPointerOverGameObject()
    returned true everywhere.
     
  14. JackRowa

    JackRowa

    Joined:
    Mar 6, 2015
    Posts:
    2
    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.