Author Topic: UIGrid.Reposition() overlaping elements  (Read 1163 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
UIGrid.Reposition() overlaping elements
« on: July 21, 2016, 01:26:23 AM »
I have a small vertical grid with 3 buttons. Depending on certain occasions i disable some of them and then call UIGrid.Reposition(). UIGrid settings are: Arrangement vertical, cell width/height 100, pivot center, sorting none, smooth true, hide inactive true. The object holding the uigrid also has tween transform (if that might affect anything)
So for some reason once i disable second two buttons, and then later enable them they overlap each other
something like this
#later            or   #
1:x=0                  1:x=0
2:x=-50               2:x=0
3:disabled            3:x=-100

I tried:
Calling .Reposition() in update
Calling .Reposition() after enabling/disabling
Calling .repositionNow to true in both cases
Setting button.transform.position   -> it moves the z: to about  -42000 (or some other large number)

Do you have any solution that might fall on your mind? I have tried searching at various places. havent really found a good solution


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid.Reposition() overlaping elements
« Reply #1 on: July 21, 2016, 11:59:53 AM »
You said you have hide inactive option turned on. This means that it will effectively ignore objects that are disabled. So if you then enable the object later, it won't be in the right position.

Setting transform.position is the wrong thing to do, that's in world space. If you must adjust something, do transform.localPosition. Keep in mind the UIGrid is a pretty simple script that, like the rest of NGUI, you have full source code for. You can add Debug.Logs in there to see what happens and what it's caused by, including its Reposition() function.