Author Topic: Adding child GameObject moves parent's position.  (Read 6625 times)

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Adding child GameObject moves parent's position.
« on: June 14, 2016, 10:23:25 AM »
Part of the UI for our game shows letters over a box background.  I have a parent UITable, which holds a child background box for each letter, and then the letters are added as needed with this code:

GameObject letter = NGUITools.AddChild( boxes[j].gameObject, letterPrefab );
letter.GetComponent<UILabel>().text = curGame.wordsArray[ i ][ j ].ToString().ToUpper();

However, after I call OnReposition on the UITable, any box with a text child gets it's position adjusted when calling OnReposition() and looks like this:



I don't actually need the background boxes to move, but if I don't call OnReposition() it gets called anyway.  Is there a way to set things up so that the boxes won't move when the child is added?

Thanks!
-Mo
« Last Edit: June 14, 2016, 10:46:34 AM by MoProductions »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Adding child GameObject moves parent's position.
« Reply #1 on: June 16, 2016, 03:47:26 AM »
UITable queries the dimensions of the children when it's calculating the bounds. In your case I suggest using a grid, not a table. Grid cells are fixed size.