Author Topic: UIGRID Reposition Crashing?  (Read 5090 times)

stran25

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
UIGRID Reposition Crashing?
« on: July 09, 2014, 03:52:11 PM »
I was wondering if anyone has had any problems when you call reposition on the uigrid because right now when I call reposition it keeps freezing/crashing the unity editor.

Thanks for the help in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #1 on: July 09, 2014, 03:59:15 PM »
All it does inside is changes the localPosition of children. Try it:

1. New scene.
2. ALT+SHIFT+S
3. Select UIRoot, ALT+SHIFT+N
4. Attach UIGrid
5. Drag the sprite over underneath UIGrid, duplicate it a few times.
6. Right click UIGrid, Execute.

stran25

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #2 on: July 09, 2014, 06:29:40 PM »
I am generating the children of the uigrid dynamically through code. I have tried calling reposition() after I have added a child to the grid and I have also tried calling reposition() after all children have been added to the grid but it keeps freezing/crashing. And also in order to add a child am I supposed to use NGUITools.AddChild() or am I supposed to be using UIGrid.AddChild();

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #3 on: July 10, 2014, 08:12:19 PM »
NGUITools.AddChild. List of grid's children is recalculated every time it's used, so using Grid's AddChild is rather pointless at this time. I will revisit this functionality after Unity 4.6.

stran25

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #4 on: July 11, 2014, 11:37:51 AM »
This is my code where I add the children but every time I try to call grid.GetComponent<UIGrid>.Reposition(); Unity crashes. I also have tried just calling grid.GetComponent<UIGrid>().Reposition(); after adding all the children but that still doesn't work. I also tried this on another computer just to make sure it wasn't my computer. I am basically trying to create a leaderboard and maybe I am approaching this the wrong way and when you call reposition does it also sort the children?

  1. foreach(int k in totals.Keys)
  2.                 {
  3.                         leaderboardsprite.name = totals[k];
  4.                         //leaderboardsprite.transform.FindChild("Label").GetComponent<UILabel>().SetDimensions(200,25);
  5.                         leaderboardsprite.transform.FindChild("Label").GetComponent<UILabel>().text = totals[k]+"      "+k.ToString();
  6.                         NGUITools.AddChild(this.gameObject,leaderboardsprite);
  7.                         Debug.Log("initialize");
  8.                         grid.GetComponent<UIGrid>().Reposition();
  9.                 }
« Last Edit: July 11, 2014, 11:44:23 AM by stran25 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #5 on: July 11, 2014, 09:00:09 PM »
Move the Reposition() call outside the foreach statement. Add all children first, and only then call Reposition().

stran25

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #6 on: July 13, 2014, 10:36:36 AM »
Ok thanks. And just one more question does the grid get sorted every time reposition is called and if so Does that mean my custom sort function is being called as well?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGRID Reposition Crashing?
« Reply #7 on: July 13, 2014, 05:31:42 PM »
Yes and yes. You could have answered that question just by adding a Debug.Log statement in there.