Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can i reference a deactivated (not public) gameobject?

Discussion in 'Scripting' started by xAmrxxxx, May 23, 2016.

  1. xAmrxxxx

    xAmrxxxx

    Joined:
    Jan 5, 2016
    Posts:
    56
    It's a child of an object. i set that child's SetActive to false when i collide with it
    Now, when a certain object triggers the parent i want to set that child's SetActive to true again.. i've tried GetComponentsInChildren but the problem is that that child's components wont show in the array because it is not active, also i can't store the child object in a public transform because it is not the same child that gets set to inactive every time (there's alot of children to the parent object). Soo is there another way of doing it? Help would be appreciated
     
  2. skalev

    skalev

    Joined:
    Feb 16, 2012
    Posts:
    264
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    There are ways to find inactive objects.

    Some options to consider
    • Get a reference to the object when it is set inactive.
    • Get and hold a reference to all children all the time
    • Set active all of the children of the object
    • Iterate ove all children and look for an inactive one
     
  4. xAmrxxxx

    xAmrxxxx

    Joined:
    Jan 5, 2016
    Posts:
    56
  5. razielanarki

    razielanarki

    Joined:
    Jun 1, 2014
    Posts:
    58
    just pass "true" as the second parameter, and it will return disabled components too.
     
  6. xAmrxxxx

    xAmrxxxx

    Joined:
    Jan 5, 2016
    Posts:
    56
    Suppose that i want to get all children with type Transform.. what should i type to do it? (Example script would be more helpful than 'do and don't' kind of answer)
     
  7. razielanarki

    razielanarki

    Joined:
    Jun 1, 2014
    Posts:
    58
    gameObject.GetComponentsInChildren<Transform> (true); :)
     
    xAmrxxxx likes this.
  8. xAmrxxxx

    xAmrxxxx

    Joined:
    Jan 5, 2016
    Posts:
    56
    thanks! that worked