Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Chaosgod_Espér on March 13, 2014, 05:16:08 PM

Title: Updating the ScrollView gives Errors..
Post by: Chaosgod_Espér on March 13, 2014, 05:16:08 PM
Hi..

Today i tried to add Components to my UIGrid at runtime.
The grid is child of a scrollview (to clip away on scrolling). And the Contents are childrens of the grid.
See:
(http://s7.directupload.net/images/140313/c6cjczeq.png)

Now i add content to the grid via Instantiate, set the Grid.transform as Parent, and update the grid via Reposition().
The instantiated contend is scaled up to 240*240*240. But that was solvable with resetting the localScales.

But at runtime, i get this Error:
Quote
NullReferenceException: Object reference not set to an instance of an object
UIScrollView.UpdateScrollbars (.UIScrollBar sb, Single contentMin, Single contentMax, Single contentSize, Single viewSize, Boolean inverted) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:488)
UIScrollView.UpdateScrollbars (Boolean recalculateBounds) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:459)
MainScript+<GetContent>c__Iterator4.MoveNext () (at Assets/Scripts/MainScript.cs:216)

Did i miss something in order to create a dynamic list of objects in a scrollable grid?
Title: Re: Updating the ScrollView gives Errors..
Post by: ArenMook on March 14, 2014, 11:36:29 AM
Use NGUITools.AddChild instead of Instantiate. It sets the parent, layer, resets the scale, etc.
Title: Re: Updating the ScrollView gives Errors..
Post by: Chaosgod_Espér on March 15, 2014, 05:37:30 PM
okay.. the error is gone with AddChild.

i´m doing it now this way:
  1. [...]
  2. contents[runnerid,runnerfield].cont_window = NGUITools.AddChild(ContentWindowGrid.transform.gameObject, ContentWindowPrefabs);
  3. [...]
  4. ContentWindowGrid.repositionNow = true;
  5. [...]
  6.  

But the Scrollview is not possible to be scrolled. Like it is not updating its content length. Doesn´t matter if i try to scroll with the mouse wheel or the scrollbar.. the scrollview isn´t moving.
Currently, there are 6 Content windows, where 4 are the maximum visible paralell on screen.. So scrolling is essential for this list ._.

How can i update the scrollview, so it recognizes it´s content size/length/amount?
Title: Re: Updating the ScrollView gives Errors..
Post by: ArenMook on March 15, 2014, 05:52:44 PM
Updating of bounds happens when you press on the object with UIDragScrollView. You can also force it by calling UIScrollView's UpdateScrollBars(true) function -- but most commonly calling UpdatePosition() is better.

If you scroll view isn't moving at all, then check to see if UIDragScrollview script is present on all the colliders.
Title: Re: Updating the ScrollView gives Errors..
Post by: Chaosgod_Espér on March 16, 2014, 05:01:50 AM
when calling UpdateScrollBars(true) or UpdatePosition(), the error i posted happens again :/


Edit:
When i try to change the value of the progress Bar/Scrollbar during testplay (with the Inspector Window), the same error appears. See:
Quote
NullReferenceException: Object reference not set to an instance of an object
UIScrollView.UpdateScrollbars (.UIScrollBar sb, Single contentMin, Single contentMax, Single contentSize, Single viewSize, Boolean inverted) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:488)
UIScrollView.UpdateScrollbars (Boolean recalculateBounds) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:459)
UIScrollView.UpdatePosition () (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:594)
UIProgressBarEditor.DrawLegacyFields () (at Assets/NGUI/Scripts/Editor/UIProgressBarEditor.cs:76)
UIProgressBarEditor.OnInspectorGUI () (at Assets/NGUI/Scripts/Editor/UIProgressBarEditor.cs:25)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d3d49558e4d408f4/Editor/Mono/Inspector/InspectorWindow.cs:850)
UnityEditor.DockArea:OnGUI()
Title: Re: Updating the ScrollView gives Errors..
Post by: ArenMook on March 16, 2014, 12:20:16 PM
Line 488 of UIScrollView is a bracket for me. Please update.