activating and deactivating child game objects in editor

Hi I used to be able to set the parent game object to active or inactive in editor by clicking the checkbox and it would ask me if I wanted to set the child objects to active or inactive. It no longer does this and I have to manually expand each child object and set it to active/inactive which takes forever if you have many child objects.

Does anyone know how to do this please?

If you’re using Unity 4, I’m pretty sure you don’t have to anymore:

http://unity3d.com/unity/whats-new/unity-4.0

It sounds like in Unity 4 if the parent is disabled, children are all disabled no matter what they’re property value is.

If you’re using Unity 3.5.x then it sounds like a bug as it should give you that prompt every time.

Use this Editor script. Works a treat and saved me a lot of work!

using UnityEngine;
using UnityEditor;

/// <summary>
///   Select the parent object and run this to set all the child objects as
///   active.
/// </summary>
public class SetAllChildObjectsActive
{
    [MenuItem ("GameObject/Set All Child Objects Active")]
    static void SetChildObjectsActive()
    {
        Selection.activeGameObject.SetActiveRecursively(true);
    }
}

One you’ve added it, just select the parent object in the hierarchy and select menu item ‘GameObject/Set All Child Objects Active’. You can then just set the parent as inactive afterwards, which will follow through to the children.

Hope this helps. :slight_smile:

1 Like