Support => NGUI 3 Support => Topic started by: AtomicBob on April 15, 2014, 01:37:31 PM
Title: What's the proper pattern for moving a widget from one panel to another?
Post by: AtomicBob on April 15, 2014, 01:37:31 PM
I'm attempting to move an object with several widgets on it to another panel temporarily at runtime. It seems like it should be very straightforward, but I can't get it to work. Here's my best guess at how it's supposed to work:
Even setting both panels as dirty doesn't work. Anyone know the right way to do this?
EDIT: It does work as expected if you disable the widget(s) before changing the parent, then reenable it afterward. Ditto with the panel's GameObject. I'm not sure this is the intended method, though.
Title: Re: What's the proper pattern for moving a widget from one panel to another?
Post by: ArenMook on April 16, 2014, 10:15:51 AM
Whenever you change the parent, you need to notify the widget via NGUITools.MarkParentAsChanged(objectThatWasReparented);
Also... never use UIPanel.RemoveWidget/AddWidget. They're not meant to be used by users. Simply changing the parent then calling MarkParentAsChanged is enough.
P.S. Drag & drop example does the re-parenting correctly if you need an example.