Search Unity

Unity 4: Use SetActive() and not affect children of the gameobject

Discussion in 'Scripting' started by eskovas, Nov 2, 2012.

  1. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Hello,

    I'm having a bit of a problem switching from Unity 3 to Unity 4 and one of the problems is the removal of the .active and .SetActiveRecursively() and both were merged into a single function, SetActive() which activates the gameobject and all of its children.
    There were also added two variables, .activeSelf and .activeInHierarchy, but both are Read Only.

    So my question is, is there a simple way to activate only the gameobject and not its children?
    I know a way but it's more complicated than a simple method implemented into the gameobject component... It would be to do a foreach for every children of the object and set those to false but it's way more complicated and less efficient than a single function.

    Thanks.
     
    Last edited: Nov 2, 2012
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Unity does not support having children active and parents deactivate any longer. You need to change your setup to accommodate the new system...
     
  3. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Well that's bad... I'm going to have to change things to be back to normal.
    Thanks for the reply :)
     
  4. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    I just have other question:
    How can i enable an object and every children through the inspector?, it's only enabling the parent and not the children.
    This didn't happen in Unity 3.5.
     
  5. Errorsatz

    Errorsatz

    Joined:
    Aug 8, 2012
    Posts:
    555
    Actually, it sounds like he's trying to do the reverse - parent active, children not active. Is that also impossible?
     
  6. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Did you check to make sure that each child is locally active?