Author Topic: switching UI Panels children not becoming visible  (Read 7489 times)

greggtwep16

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
switching UI Panels children not becoming visible
« on: November 16, 2014, 11:47:49 PM »
I've been having an issue with switching UIPanel's not always displaying all the children (buttons, labels, etc) on the newly activated panel and would like some advice.  Code posted at the bottom of how I switch panels (the animation is just a simple fade out/in on UIRoot).  The funny thing it isn't deterministic sometimes all the buttons/labels etc. do become visible and sometimes not it is very weird (but it happens frequently enough so definitely something is wrong).  The children items on the panel will always become enabled its just sometimes they aren't visible (including all components on the children).  I have verified that the depth fields are not duplicates on any of the children item so that isn't the issue.  I'm using the latest version of NGUI.

  1.         IEnumerator switchActivePanel(UIPanel activate, UIPanel deactivate) {
  2.                 root.animation.Play();
  3.                 yield return new WaitForSeconds(.15f);
  4.  
  5.                 NGUITools.SetActive (deactivate.gameObject, false);
  6.                 NGUITools.SetActive (activate.gameObject, true);
  7. }

2 questions:
1.  Is there any way to tell NGUI to clear its cache (whether it's the drawcall, hierarchy, etc) so I can in effect set the whole thing to dirty?  (I've tried markparentaschanged with no luck)
2.  Any Ideas of where to focus the investigation for visibility issues even though the objects always get enabled correctly?
« Last Edit: November 17, 2014, 12:20:14 AM by greggtwep16 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #1 on: November 17, 2014, 09:16:18 AM »
Whenever you change the parent of something you need to NGUITools.MarkParentAsChanged. You should also never change the widget's panel yourself. Just transform.parent.

greggtwep16

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #2 on: November 17, 2014, 02:06:38 PM »
Changing the code to the following did not work (sometimes has child labels,buttons, etc  not visible).  I am only switching the active panel I'm not changing/moving any of the buttons/labels underneath or anything like that.  Just swapping out which panel is visible.

  1.         IEnumerator switchActivePanel(UIPanel activate, UIPanel deactivate) {
  2.                 root.animation.Play();
  3.                 yield return new WaitForSeconds(.15f);
  4.  
  5.                 NGUITools.SetActive (deactivate.gameObject, false);
  6.                 NGUITools.SetActive (activate.gameObject, true);
  7.  
  8.                 NGUITools.MarkParentAsChanged (activate.gameObject);
  9.  
  10.         }

Just to make sure I'm explaining it clearly I have a Main Menu system like below (below is simplified but same idea).

-UIRoot
    -UIMainPanel
        -LabelTitle
        -PanelButton1
        -PanelButton2
    -UIOptionsPanel
        -LabelOptionsTitle
        -PanelButtons

Only one panel is ever enabled at a time and I'm using the above function to try and switch the panels.  However, sometimes the buttons under the panels don't become visible (though they are enabled).  I've looked at your example menu included and it does originally have the options panel disabled and then you enable it, although at first glance it looks like your animations do the work not code (I couldn't actually find where the options panel got enabled in the example so I assume its the animation).

In my project the animation is just a generic quick fade to black and then back on the UIRoot I don't really want to make custom animations for all the panels as in the future I envision I'll have quite a few.  Any advice/guidance would be appreciated.
« Last Edit: November 17, 2014, 02:12:01 PM by greggtwep16 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #3 on: November 18, 2014, 05:17:47 AM »
What are you animating there? You can't animate private variables like "MAlpha". That's private. It should not be exposed and the fact that unity makes it visible in the animation is a very old Unity bug.

You need an intermediate class to animate things, since Unity won't let you work with properties, and everything in NGUI should be going through properties.

Have a look at the AnimatedAlpha class. Use it, and animate its alpha value instead.

greggtwep16

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #4 on: November 18, 2014, 04:02:38 PM »
Thanks! I was indeed using mAlpha and didn't realize since I just added it in the animation window that it was private.  Adding the animateAlpha component to UIRoot and having the animation use it seems to clear up the indeterminate behavior and the buttons, labels, etc always seem to be visible when switching panels.

djock

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #5 on: May 17, 2015, 06:19:04 AM »
Hello guys,

I still have this issue. I have a UIPanel which I activate from the script
  1. if (Input.GetKeyDown (KeyCode.Escape))
  2.     {
  3.          Debug.Log("Close");
  4.          if(!quitGame.gameObject.activeSelf)
  5.          {
  6.              NGUITools.SetActive (quitGame.gameObject, true);
  7.              NGUITools.MarkParentAsChanged (quitGame.gameObject);
  8.              //Debug.LogError("Quit panel after ESC: " + quitGame.gameObject.activeSelf);
  9.          }
  10. }
  11.  

And the UIPanel is dismissed through the UI Window Button script (hide). But when I try to reactivate the window...it is not visible (I can see in the Inspector that in fact the UIPanel is active). Just started with Unity - NGUI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #6 on: May 22, 2015, 03:33:26 PM »
I don't see anything particularly wrong with your showing code.

gameObject.activeSelf = false; <-- this is enough to disable something
gameObject.activeSelf = true; <-- this is enough to re-enable it.

There is no need to mark the parent as changed.

djock

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: switching UI Panels children not becoming visible
« Reply #7 on: May 26, 2015, 03:31:45 PM »
I sorted it in the meantime, changing NGUI.SetActive with UIWindow.Show(go);/.Hide(go);. Really sexy.
Thanks for replying.