Search Unity

GameObject.active warning CS0618: obsolete

Discussion in 'Scripting' started by karenkrane, Jul 25, 2013.

  1. karenkrane

    karenkrane

    Joined:
    Nov 16, 2012
    Posts:
    15
    Hi. I'm using the ActivateTrigger.cs script (found here: https://github.com/ehelms/Forceful-...ts/Standard Assets/Scripts/ActivateTrigger.cs) and getting the active is obsolete warning for the lines:
    Code (csharp):
    1. case Mode.Activate:  targetGameObject.active = true;
    and

    Code (csharp):
    1. case Mode.Deactivate:   targetGameObject.active = false;

    I tried both activeSelf and activeInHierarchy, neither of which work. How do I update this code for Unity 4.2?

    cheers!
     
  2. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    I think Unity should tell you what to use instead of the obsolete methods (I met such a situation some time ago).
    Also try to use targetGameObject.SetActive(true).
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The warning says to use GameObject.SetActive, so that's what you should do.

    --Eric
     
  4. karenkrane

    karenkrane

    Joined:
    Nov 16, 2012
    Posts:
    15
    Thanks. I see it doesn't work with = but needed to be changed to setActive (true).
     
    Last edited: Jul 25, 2013