Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: manituan on June 05, 2014, 05:38:50 AM

Title: Clear BetterList from UIWrapContent
Post by: manituan on June 05, 2014, 05:38:50 AM
Hi,

I have a WrapContent component and I remove/instantiate elements underneath this gameObject. The issue I have is that after I clear all the children destroying them, UIWrapContent is trying to access to those destroyed transforms OnDrag:

  1. MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
  2. UnityEngine.Transform.get_localPosition ()
  3. UIWrapContent.WrapContent () (at Assets/NGUI/Scripts/Interaction/UIWrapContent.cs:157)
  4. UIWrapContent.OnMove (.UIPanel panel) (at Assets/NGUI/Scripts/Interaction/UIWrapContent.cs:62)
  5. UIPanel.set_clipOffset (Vector2 value) (at Assets/NGUI/Scripts/UI/UIPanel.cs:400)
  6. UIScrollView.MoveRelative (Vector3 relative) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:653)
  7. UIScrollView.MoveAbsolute (Vector3 absolute) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:667)
  8. UIScrollView.Drag () (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:789)
  9. UIDragScrollView.OnDrag (Vector2 delta) (at Assets/NGUI/Scripts/Interaction/UIDragScrollView.cs:112)

Thanks.
Title: Re: Clear BetterList from UIWrapContent
Post by: manituan on June 05, 2014, 06:07:32 AM
I've found out that this issue is only happening with UIWrapContent, not with UIGrid. So meanwhile I'll use a grid instead.
Adding this to UIWrapContent line 154 fixes the errors, but there is a gap between the elements that currently are and the ones I destroyed before. Thanks.

  1.         for (int i = 0; i < mChildren.size; ++i)
  2.                         {
  3.                                 Transform t = mChildren[i];
  4.  
  5.                                 if(t == null)
  6.                                 {
  7.                                         continue;
  8.                                 }
  9.  
Title: Re: Clear BetterList from UIWrapContent
Post by: ArenMook on June 06, 2014, 02:00:35 AM
Deleting children of a wrapped content script is a big no-no. It caches this list on startup so that it's able to reposition them properly. If you're deleting them, you need to let the script know (but ideally you'd delete the wrap content script and create a new one instead).