Search Unity

GameObject.active' is obsolete

Discussion in 'Scripting' started by uistudios, Dec 5, 2012.

Thread Status:
Not open for further replies.
  1. uistudios

    uistudios

    Joined:
    Apr 6, 2009
    Posts:
    46
    Hi guys, I am using a simple if statement script that works very well on both iOS/Web but below shows this "warning"!
    the if statement simply check to see if a certain game object is visible before it is allowed to run the remaining code...

    if (Cleared.gameObject.active || Failed.gameObject.active){

    WARNING: 'UnityEngine.GameObject.active' is obsolete. GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy


    what would be the correct way to check if gameObjects are active using an if statement!?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    well, what exactly are you trying to determine?

    SetActive can be ignored, because that's to set active.

    testing active is 'activeSelf':
    http://docs.unity3d.com/Documentation/ScriptReference/GameObject-activeSelf.html

    and 'activeInHierarchy':
    http://docs.unity3d.com/Documentation/ScriptReference/GameObject-activeInHierarchy.html

    Check what each returns, and decide for yo'self.


    If you are just concerned if it's active locally to itself, activeSelf is your choice. If you want to know if it's active in the scene, activeInHierarchy is your choice.
     
    TitanFish likes this.
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    .activeInHierarchy is basically the equivalent of the old .active.

    --Eric
     
  4. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    Yeah but;
    and..

    and with SetActive():

    All these errors from: Assets/Standard Assets/Scripts/General Scripts/ActivateTrigger.cs

    The funny thing is, this fix for the active one worked once for me, but now on this project is doesn't.

    *EDIT: uhg, I need to get more sleep, I didn't put the true and false values inside the SetActive brackets. derp. Not sure about the other errors.
     
    Last edited: Dec 10, 2012
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Only if you've modified it; the standard version that comes with Unity uses .active, which generates a warning about being obsolete but still works for now.

    --Eric
     
  6. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    I tolerate no errors in my projects, yellow or otherwise.
     
  7. jaxx0rr

    jaxx0rr

    Joined:
    Aug 25, 2013
    Posts:
    23
    yeah well when I change it to setActive I get

    Assets/Scripts/MAIN.js(643,44): BCE0019: 'setActive' is not a member of 'UnityEngine.GameObject'. Did you mean 'active'?

    what is up with that ??
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You spelled it wrong. It's a function, not a variable.

    --Eric
     
  9. DryTear

    DryTear

    Joined:
    Nov 30, 2012
    Posts:
    312
    Code (csharp):
    1.  
    2. gameObject.SetActive(false);
    3.  
     
  10. jaxx0rr

    jaxx0rr

    Joined:
    Aug 25, 2013
    Posts:
    23
    oh rite its SetActive not setActive
     
  11. albboy

    albboy

    Joined:
    Oct 20, 2013
    Posts:
    1
    Hi, the correct way is gameObject.SetActive(false); or gameObject.SetActive(true);
     
    yl_rhs likes this.
  12. yl_rhs

    yl_rhs

    Joined:
    Jan 30, 2015
    Posts:
    1
    Thank you sooo much! I had been trying to figure out why SetActive = true or false, and activeInHierarchy gives me errors when .active works and still gives me errors.
     
Thread Status:
Not open for further replies.