Author Topic: Position child objects at runtime  (Read 6506 times)

Medico

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Position child objects at runtime
« on: January 02, 2016, 12:13:34 PM »
Hi,

I'm using NGUI.AddChild on a Grid to add items into a scroll view. But because at Runtime the Grid component disables itself they don't position nicely and stack on top of each other. When I tick the Grid component back on at runtime it repositions everything nicely before turning itself off again. How can I have it reposition things at runtime?

Thanks,
Jack

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Position child objects at runtime
« Reply #1 on: January 03, 2016, 03:41:58 PM »

Medico

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Position child objects at runtime
« Reply #2 on: January 03, 2016, 05:50:17 PM »
So would I add that line in a script placed on my grid object and run it every time I spawn a new child?

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Position child objects at runtime
« Reply #3 on: January 04, 2016, 10:00:50 AM »
Run it when you've finished making changes. If you add your children in batches, spawn it at the end.

Medico

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Position child objects at runtime
« Reply #4 on: January 04, 2016, 10:38:12 AM »
Thanks that's worked!  :)

I used GetComponent<UIGrid>().Reposition(); on a script placed on my Grid.