Author Topic: UIWrap Content  (Read 7607 times)

johnessy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
UIWrap Content
« on: February 22, 2016, 02:13:27 PM »
Hey fella's

I am having some issues with UIWrapContent. I create my object dynamically and on start. On start the wrap works perfect! BUT when I delete those buttons and create new ones then swipe to move them i get tonnes of errors. I have tried to delete the WrapContent then re-add it before buttons are created, after they are created, I sorted after created and still it will not work, i just keep getting this error.

What am i doing wrong?

Thanks

  1. MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
  2. Your script should either check if it is null or you should not destroy the object.
  3. UnityEngine.Transform.get_localPosition () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineTransformBindings.gen.cs:40)
  4. UIWrapContent.WrapContent () (at Assets/NGUI/Scripts/Interaction/UIWrapContent.cs:193)
  5. UIWrapContent.OnMove (.UIPanel panel) (at Assets/NGUI/Scripts/Interaction/UIWrapContent.cs:92)
  6. UIPanel.set_clipOffset (Vector2 value) (at Assets/NGUI/Scripts/UI/UIPanel.cs:416)
  7. UIScrollView.Press (Boolean pressed) (at Assets/NGUI/Scripts/Interaction/UIScrollView.cs:759)
  8. UIDragScrollView.OnPress (Boolean pressed) (at Assets/NGUI/Scripts/Interaction/UIDragScrollView.cs:95)
  9. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  10. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:1503)
  11. UICamera:ProcessPress(Boolean, Single, Single) (at Assets/NGUI/Scripts/UI/UICamera.cs:2224)
  12. UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:2453)
  13. UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:1888)
  14. UICamera:ProcessTouches() (at Assets/NGUI/Scripts/UI/UICamera.cs:2002)
  15. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:1689)
  16.  

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: UIWrap Content
« Reply #1 on: February 22, 2016, 03:16:36 PM »
Unless I am just not understanding what you are saying, I'm guessing you have set the transform of some object as the parent of another object (child object).  When you remove the object that is the parent, you have the children trying to access a transform that no longer exists.  You can either temporarily change it via SetParent() to something else, then change it back, or even better - just dynamically change the button info instead of removing it and re-adding it.  Or, you could add them all at once, and keep some hidden, and shuffle them around (make active/hide) depending on what the user is doing.

Cheers.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrap Content
« Reply #2 on: February 22, 2016, 07:15:03 PM »
You should never be adding/removing stuff under UIWrapContent. The whole point of that script is to reuse existing items to populate its contents. It keeps a list of these items that gets created when the script starts up. UIWrapContent responsible for them, not you. Instead, set the UIWrapContent.onInitializeItem delegate if you want to control the content that shows up.

johnessy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: UIWrap Content
« Reply #3 on: February 23, 2016, 06:43:19 AM »
Ah right, so its not as simple as just adding and removing from the content? I thought that removing the component then creating it along with new children would off worked.

As for the OnInitialize what do you mean control what shows up ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrap Content
« Reply #4 on: February 25, 2016, 09:58:58 PM »
OnInitialize lets you change each item based on its position. For example change the label's text to display an appropriate number based on its wrapped index.