Author Topic: setActive does not work?  (Read 3443 times)

KardinalRatz

  • Guest
setActive does not work?
« on: August 01, 2013, 08:47:02 AM »
Ok my problem is probably really easy but i cant see it at the moment.

I have a Gameobject with panels and stuff that should not be active all the time.

I now have in the start function:
  1. buyMenu = GameObject.Find("BuyMenu");
  2.  

and in the update function:

  1. if(Input.GetKey(KeyCode.K) && isActive == false)
  2. {
  3.    NGUITools.SetActive(buyMenu, true);
  4. }
  5.  

(and yes i declared the variable and isActive is false ofc)

The problem now is i can deactivate it alright with: NGUITools.SetActive(buyMenu, false);
but i cant activate it with: NGUITools.SetActive(buyMenu, true);

The biggest problem is that i dont get any error messages so any help would be appreciated.

missingno

  • Guest
Re: setActive does not work?
« Reply #1 on: August 01, 2013, 03:01:28 PM »
  1. buyMenu = GameObject.Find("BuyMenu");
  2.  

This will only work if your BuyMenu GameObject is active when calling this (which it would be if you can de-activate it afterwards). It will return null if it's not found (which if it is not active, is the case), so later when you try to activate it I assume buyMenu is null so nothing happens.

An easy way around this is to make buyMenu public and set it in the inspector instead of using GameObject.Find.

KardinalRatz

  • Guest
Re: setActive does not work?
« Reply #2 on: August 02, 2013, 01:23:59 AM »
Quote
This will only work if your BuyMenu GameObject is active when calling this (which it would be if you can de-activate it afterwards). It will return null if it's not found (which if it is not active, is the case), so later when you try to activate it I assume buyMenu is null so nothing happens.

An easy way around this is to make buyMenu public and set it in the inspector instead of using GameObject.Find.

Yes i call GameObject.Find when it is still active. It is really strange, especially since i dont get any errors.

missingno

  • Guest
Re: setActive does not work?
« Reply #3 on: August 02, 2013, 08:42:51 AM »
I'm not sure then, without seeing the project or sample reproducing the problem.

Aside form putting Debug.Logs in places to make sure things are being called and variables are what they should be, and/or using the inspector rather than GameObject.Find.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: setActive does not work?
« Reply #4 on: August 02, 2013, 11:07:48 AM »
What does "isActive" represent? Is that if the gameObject is inactive? Remember that no monobehavior methods run on disabled gameobjects, even Update().