Deactivating/Activating multiple gameobjects in editor with selection

Is there anyone who knows a way to deactivate multiple gameobjects in the unity editor? Using the the checkbox for the GO only deactivates/activates a single object on multiple selection. I think you could quite easily do it by creating a editor scripts, but I thought maybe someone could point my in the right direction.

I've made the following editor scipt which is really what I'm looking for. Creating parent GO isn't the best idea since my 3d model and its sub components often change to a new version of the 3d object (application in development).

Below is some ready to use code:

using UnityEngine;
using System.Collections;
using UnityEditor;

public class MySelectionScripts : MonoBehaviour {

    [MenuItem ("Custom/Selection/Deactivate objects %#d")]
    static void DoDeactivate()
    {
        foreach (GameObject go in Selection.gameObjects)
        {
            go.active = false;
        }
    }

    [MenuItem("Custom/Selection/Activate objects %#a")]
    static void DoActivate()
    {
        foreach (GameObject go in Selection.gameObjects)
        {
            go.active = true;
        }
    }

}

Hotkeys are:

CTRL+SHIFT-A - Activate selected objects

CTRL+SHIFT-D - Deactivate selected objects

The thing I was looking for was the UnityEditor.Selection class :)

Documentation here

I suppose you could select them, assign them to a single parent GameObject, and then deactivate that parent. Then it would be up to you whether to leave them under that parent to tidy up your heirarchy view, or remove them again.

Unity 3.5 supports multi-object editing.

In the Inspector, at the very top, by the object name is a checkbox which will activate/deactivate objects. If the object is a parent, Unity will prompt you about activating/deactivating all children.

Editor scripts would be an easy solution for things like deactivating whole layers, tags or a groups of objects.

hi! I have only been using Unity for a shot time now, and im trying to get into scripting. I tried out the script above, it works really well but i would really like it to affect all of the children under the parent. Is there an easy addition to the script for that?

Thank you very much!

Just to improve on Rasmus’s answer, Please take a look at the link to my blog post.

Improvements:

  1. One key to toggle between active and not active
  2. Uses ‘gameObject.SetActive’ for unity 4.x users, which activates or deactivates the entire tree

Toggle GameObjects in the Editor using shortcut

Not sure which version they added it in, but ALT+SHIFT+A now toggles single/multiple selection between ACTIVE/INACTIVE now.

Check if you have GameObject>Toggle Active State in your editor.