Author Topic: Reloaded UIGrid elements start offscreen  (Read 2761 times)

ChristopherDrum

  • Guest
Reloaded UIGrid elements start offscreen
« on: October 01, 2012, 02:43:36 AM »
I will first preface by saying I've only been using Unity and nGUI for 3 weeks now. So there may be a simple solution that I am overlooking to this problem.

I have two UIGrid displaying content. Both are scrollable and both work just fine upon panel load.
Clicking a button in the bottommost UIGrid updates the contents of the topmost UIGrid. In this way, the bottommost acts like a content selector, and the topmost is the content display. Touching a piece of content in the upper grid goes to a details screen.

Clicking the buttons does indeed load up and populate the upper content properly. Clicking a piece of content properly navigates to its detail screen. So, functionally everything is working as expected.

However, when the buttons are reloaded in either UIGrid, they come on very very far to the right of the screen. A single click inside the scroll view and they buttons slide in from the right and position themselves properly. I cannot identify why they are positioned absolutely perfectly upon first panel load vs. when the data inside them is refreshed.

So it feels like the scroll views are expecting one extra trigger or event to make them behave properly. I have followed the instructions about the order of events when loading up new content into an existing scrolling UIGrid. That being UIDraggablePanel.ResetPosition() -> make the content changes -> UIGrid.Reposition() ->UIDraggablePanel.ResetPosition()

One thing I'm doing that perhaps is a little different is that I am completely removing the existing content from a UIGrid before putting in the new content. I've combined these into the "make the content change" step, but had this same issue even when performing two discrete sets of content changes: the first being to delete the content, the second being to put in new content.

Thanks in advance for any insight that can be offered on this use case of the UIGrid and UIDraggablePanel

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reloaded UIGrid elements start offscreen
« Reply #1 on: October 01, 2012, 04:24:48 PM »
Are you re-populating one grid by destroying items first and then adding a new set? Destroyed objects don't get removed from the transform's list of children unless you manually set their parent to null before destroying them. That sounds like what you're missing.

ChristopherDrum

  • Guest
Re: Reloaded UIGrid elements start offscreen
« Reply #2 on: October 01, 2012, 07:58:00 PM »
That is exactly what I've been doing. In looking at the transform hierarchy, everything seemed fine so I didn't think anything else was needed with regard to parents. I'll give that a shot and log my result here for future posterity.

------------------------------

Quick update: that totally did the trick. Thank you, I never would have considered that. In these early learning stages, I thought NGUITools.Destroy(someobject) was enough.
« Last Edit: October 01, 2012, 08:01:47 PM by ChristopherDrum »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reloaded UIGrid elements start offscreen
« Reply #3 on: October 01, 2012, 11:29:40 PM »
You know, you actually bring a good point. There is no reason why I can't add a transform.parent = null to NGUITools.Destroy. I'll try that locally and see if I notice any odd effects.