# Unity - SetActive() on GameObject dont works on child's objects

I have the following line of code:

GameObject.Find("_obstacles").SetActive(false);


It serves to leave an inactive object, but the children of this object are not getting with the same status.

My result is:

The objects children do not inherit the parent object state (as stated in the > documentation of Unity)!

But the obsolete method "SetActiveRecursively()" works for me! O.o The Very strange, no?

Have you tested if the child objects really are active in game? The behavior has changed from Unity3 when SetActiveRecursively was needed. Since Unity4, setting the parent to inactive should also deactivate the child objects (in game) even though it still shows them as active in the inspector.

See the documentation for GameObject.SetActive()

Note that a GameObject may be inactive because a parent is not active. In that case, calling SetActive() will not activate it, but only set the local state of the GameObject, which can be checked using GameObject.activeSelf. This state will then be used once all parents are active.

If you really do want to deactivate the child objects, even when the parent is reactivated, then you will need your own function. Unity doesn't provide it anymore.

Here is a link to a solution that you can copy-paste to your own code.

• Thanks @Fuzzy Logic But i need set active false children's too! Not "only set the local state of the GameObject"... I have to make a way for this?
– Igor
Sep 14 '15 at 5:51
• Yes. If you specifically want the children to also be deactivated (even after you reactivate the parent), then you will need your own function. I've updated my answer. Sep 14 '15 at 5:58