Author Topic: Dynamicly filled NGUI table does not Reposition() properly  (Read 4829 times)

Forrest Gimp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Dynamicly filled NGUI table does not Reposition() properly
« on: March 20, 2015, 03:12:33 AM »
Hello forum!

I have posted this question to unityanswers as well, but so far have not received any response (I admit I only posted it yesterday, so something might still turn up there), and I thought it wouldn't hurt to post it here as well.

I have a table in a scrollview which I dynamically fill from code. I iterate through an array of dataobjects, filling the data into a prefab-widget. This part works flawlessly.
After the elements are all in the table I call the Reposition-method, but it is not properly executed. The padding between the elements in the table is much wider than I have set it. The only ways to properly Reposition() the tables elements I have found so far are a) right-clicking the table and choosing "execute" from the context-menu (which the end-user obviously can't do) and b) adding Reposition() to the update-function having it execute every frame (sounds like a bad idea considering performance?)

What I tried so far:
  • putting Reposition() in Update() with a boolean/if-condition that makes it execute only once
  • trying the same with LateUpdate()

I have not had any success so far. The functions themselves work ok, but they seem to have no effect on the table.

  1.  
  2.     for(int i = 0; i < _items.Length; i++)
  3.     {
  4.    
  5.         var itemInstance = NGUITools.AddChild(ItemsPanel, ItemPrefab);
  6.         var item = itemInstance.GetComponent<PrefabScript>();
  7.         item.Icon.SetTexturePath = _items[i].IconPath;
  8.         item.Level.text = _items[i].text;
  9.         item.NotPresent.SetActive(_items[i].CurrentWeapon);
  10.     }
  11.    
  12.     // make table sort itself
  13.     // it doesn't work properly, no clue why
  14.     ItemsPanel.GetComponent<UITable>().Reposition();
  15.  
  16.  

caiorosisca

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Dynamicly filled NGUI table does not Reposition() properly
« Reply #1 on: March 20, 2015, 09:11:10 AM »
I've had a similar issue a while back, I had a store with different categories and each time I filled the table with a different category it wouldn't reposition properly.
What I had to do was to loop throught all children in the table set it's parent as null instead of the table(even destroying the objects didn't solve the problem) and them add the new itens, after all that reposition them.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamicly filled NGUI table does not Reposition() properly
« Reply #2 on: March 22, 2015, 07:58:26 AM »
Simply adding children doesn't actually add them immediately. They're there, but they have not yet had a chance to find their panels yet. No panels means they aren't visible yet.

To force them to get added, use NGUITools.ImmediatelyCreateDrawCalls(tableGameObject);