Author Topic: Clear BetterList from UIWrapContent  (Read 4076 times)

manituan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Clear BetterList from UIWrapContent
« 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.

manituan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Clear BetterList from UIWrapContent
« Reply #1 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.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clear BetterList from UIWrapContent
« Reply #2 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).