Search code examples
c#parent-childunity-game-enginengui

Reparenting prefabs between to panels in Unity3d (NGUI)


Not sure this is the best forum for Unity3d/NGUI questions but give it a try...

I am trying to move a gameobject from a scrollable panel to a normal panel by reparenting it.

firstGameObject.transform.parent = secondGameObject.transform;

firstGameObject is initially child of a clipped scrollable panel. The transform seems to move just fine in the hierarchy and no longer becoming scrollable. But it is still clipped like it was a child of the clipped panel.

Any ideas?

Edit: Someone at NGUI's forum suggested calling Refresh() on both uipanels, but it had no effect. http://www.tasharen.com/forum/index.php?topic=1941.0


Solution

  • Finally got it working. The correct way was to call CheckParent() on each widget in the old panel after reparenting.

    UIPanel smallPanel = NGUITools.FindInParents<UIPanel>(firstGameObject);
    List<UIWidget> list = new List<UIWidget>(smallPanel.widgets.buffer);
    
    foreach (UIWidget widget in list)
    {
        if (widget != null)
        {
            widget.CheckParent();
        }
    }