Author Topic: How to force UIPanel child widgets to switch to a higher panel on panel disable?  (Read 2331 times)

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
I'm having a bit of trouble with an exotic case: for a certain screen transition type, I parent an object with a panel hosting some widgets to another object with a texture clipped panel, play some animations with higher-level texture clipped panel, then restore the hierarchy back. Trouble is, I can not figure how to disable the moved panel for the duration of that scene without killing the rendering of all child widgets.

To explain, here is the standard hierarchy:

Clipped panel (enabled)
Normal panel (enabled)
- Widget


And here is what happens for the duration of screen transition:

Clipped panel (enabled)
- Normal panel (disabled)
- - Widget


Problem is, the moment I disable the normal panel, every single widget stops rendering, probably because it's supposed to do that due to UIPanel OnDisable method. But I don't want that: I want the widgets to continue being rendered, just using the higher panel in the hierarchy: clipped one. And I'm unable to do that. So far I have tried lots of combinations and different orders of normal UIPanel component .enable setting, widget.ParentHasChanged() calls, direct widget.panel parameter reassignment, panel Refresh() calls, and some other methods, but nothing seems to work - absolutely invariably, once I disable the normal panel, every single widget linked to it will disappear.

The only way to get the desired behavior I have found was to destroy the UIPanel manually from the inspector. That's obviously very undesirable way of doing things, I'd prefer not to have a hassle of caching all panel properties to recreate it later and I'd prefer not to risk GC rushing in during 1 second long buttery smooth animation. I just need to replicate what happens to child widgets when a panel is removed, without actually removing (only disabling) it. But I'm not seeing any OnDestroy behavior in UIPanel, so I'm not sure how exactly widgets actually move under command of a higher panel. It's reliably happening and it's exactly what I need, but I'm unable to track how it's done. Can someone shine a light on that?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
You have to reparent the widget to the clipped panel instead. You can have a disabled panel between the drawing panel and the widget - then the disabled panel IS the drawing panel for that widget, and because it's disabled the widget is disabled. This is intended behavior, afaik.

You may be able to call ParentHasChanged() on the widget and make it change to the other panel, but I'm not sure if it will work as you expect.

bac9

  • Full Member
  • ***
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 113
    • View Profile
Yeah, ParentHasChanged has zero effect unless the panel in the middle is destroyed and not just disabled.

I can easily get every widget and reparent it to a new panel, but I don't think it would be a good idea because I will be completely unable to restore the old scene hierarchy afterward. It's one thing to parent an object neatly holding stuff inside, it's another to parent every single UIWidget that was sitting god knows how deep in the hierarchy. I'm just animating a screen transition by this texture-clipped panel, so all hierarchy has be in it's initial state just a second later, the less reshuffling, the better.

I guess I'll try getting transform children instead of UIWidget references, should probably work without breaking stuff. I'd rather not use a panel-less empty object for that.
« Last Edit: November 03, 2014, 06:40:05 AM by bac9 »