Author Topic: Existing NGui widgets added to scrollview via script not clipping  (Read 3120 times)

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
I currently want to create a dynamic list (and am using a grid), and want to avoid using Instantiate due to mobile concerns for widgets.

My idea is to have my elements already created (and under the grid gameobject), and just hidden off screen at Start() by parenting them to a gameobject above the grid and move them off screen.

Then when they are needed, I'll reparent them to the grid, move them under existing elements, and then use UIGrid.Reposition() to sort them. This seems to work fine, except when the elements exceed the scrollview dimensions, they don't clip. They used to clip in the editor, and seem to just fine, but they stop clipping when moved around during runtime.

I attached my current hierarchy and scene / play view setups (I'm unsure how to embed that into this post directly).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Existing NGui widgets added to scrollview via script not clipping
« Reply #1 on: June 21, 2015, 08:23:19 PM »
Reparenting isn't enough. You need to inform the widgets that the parent has changed: NGUITools.MarkParentAsChanged

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Existing NGui widgets added to scrollview via script not clipping
« Reply #2 on: June 22, 2015, 12:27:31 AM »
Thanks! This is what I was missing. Now it works perfectly.

I wish there was a topic that discussed the procedure for dynamically moving elements around. Maybe add it to the FAQ?