Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Euthyphro on August 24, 2014, 01:51:58 AM

Title: NGUITools.SetActive(GameObject, True) does not activate panel
Post by: Euthyphro on August 24, 2014, 01:51:58 AM
I have a panel which includes a UISprite and UITable. From a different panel I deactivate it on Start() and then activate it when a button is clicked. The problem is that it will not enable unless the button is clicked twice. There is no error message. First click the button recognizes the button is clicked (printed to debug log to make sure) but the panel is not enabled, second click it does enable the panel. Just to screw around I even tried "NGUITools.SetActive(connectToServerUI, true);" twice in a row and still it did not activate. It only activated if the button was clicked a second time even though the first click is clearly registered given the counter increases with all clicks accounted for.

  1.  
  2.         GameObject connectToServerUI;
  3.         UIButton button;
  4.         void Start ()
  5.         {
  6.                 connectToServerUI = GameObject.Find("Container - Connect to Server Box");
  7.                 button = (UIButton)this.GetComponent(typeof(UIButton));
  8.             //  StartCoroutine(Disable());
  9.         NGUITools.SetActive(connectToServerUI, false);
  10.         }
  11.  
  12.         //tried quick coroutine for testing purposes to see if this has any effect, which it doesn't.
  13.         IEnumerator Enable()
  14.         {
  15.  
  16.                 NGUITools.SetActive(connectToServerUI, true);
  17.                 yield return null;
  18.         }
  19.         IEnumerator Disable()
  20.         {
  21.                 NGUITools.SetActive(connectToServerUI, false);
  22.                 yield return null;
  23.         }
  24.         int clicks = 0;
  25.         public void OnClick()
  26.         {
  27.                 clicks ++;
  28.         //      StartCoroutine(Enable());
  29.                 NGUITools.SetActive(connectToServerUI, true);
  30.         Debug.Log("Clicks "+clicks);
  31.         }
  32.  

Any suggestions on this? It's driving me crazy. I tried a coroutine because of another thread on this forum suggested it, however, I can't see how that would make any difference. I also tried NGUITools.SetActiveChildren and NGUITools.SetActiveSelf but both had no effect.

Using Unity 4.5.3 and NGUI 3.5.x. Unless there is a dire reason to upgrade to 3.7 which would fix huge bugs, I do not want to upgrade given that last time I upgraded NGUI tools it broke half my project and resulted in days extra work just to reconfigure everything.
Title: Re: NGUITools.SetActive(GameObject, True) does not activate panel
Post by: ArenMook on August 24, 2014, 07:31:52 PM
I would first always try to upgrade to the latest. 3.5 is quite a bit older than 3.7.1. I can think of nothing that would cause the behaviour you're describing, but GameObject.Find will not find disabled objects. You should be referencing things in a public variable set in inspector instead.