Author Topic: dynamically populated UIGrid inside UIDraggablePanel messed up clipping  (Read 2068 times)


  • Guest
I have the following setup:

             -Button 1
             -Button 2

This is for a menu that changes, so I remove items from the Grid and add items to the Grid dynamically.
The DraggablePanel is set up with soft clipping, scrolling in the vertical/Y direction only, Restrict Within Panel, and Disable Drag if Fits.

When the program runs and items are added to the Grid, the DraggablePanel has an unwanted change in the clipping center X coordinate. The Y coordinate moves as it should, with the scrolling feature, but the X coordinate change makes the menu unusable. I would like to simply reset the clipping center X to zero but I don't see a function to do that. Even better, I would like to identify the cause rather than treating the symptom.

Any ideas?


  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
I am currently struggling with a similar issue.  Here is the advice I have so far:

1.  When you're adding your UIDragPanelContents items at run time, be sure to set their .draggablePanel member to the master UIDraggablePanel

2.  After adding new items to the UIGrid at run time, be sure to call grid.Reposition();

3.  After calling grid.Reposition(), call .UpdateScrollBars( true ) and .ResetPosition() on the master UIDraggablePanel.

Here is some code from our app:

  1.                 foreach( var entry in itemHistoryList )
  2.                 {
  3.                         var newHistoryItemObj = NGUITools.AddChild( itemHistoryGrid.gameObject, historyItemPrefab );
  4.                         var dragPanelContents = newHistoryItemObj.GetComponent<UIDragPanelContents>();
  5.                         dragPanelContents.draggablePanel = masterDragPanel;  // masterDragPanel is a UIDraggablePanel
  6.                 }
  8.                 itemHistoryGrid.Reposition();
  9.                 masterDragPanel.UpdateScrollbars( true );
  10.                 masterDragPanel.ResetPosition();


  • Guest
Thanks. I'm already calling reposition() and resetPosition() after the child items are added. I'll add resetScrollBars().  I also find it necessary to reset the scale, as on occasion the scale of the child items is set to <0,0,0> in this process. Very strange but the workaround is straightforward.

I should also add that occasionally the entire DraggablePanel will shift to the side after a drag. It shifts slowly, as if the bounds calculations have shown that an autoscroll is necessary. But again, the X scroll factor is set to 0, so I don't think that should be happening either.