Is there a keyboard shortcut for setting an object active/inactive?

While I’m browsing the Hierarchy using the keyboard, is there a shortcut to toggle active on the selected object, or am I forced to click the inspector using the mouse?

4 Answers

4

There is a menu item for this now. GameObject → Toggle Active State, with shortcut Alt-Shift-A

Not sure when they removed this but you can no longer use the Alt+Shift+A hotkey anymore.

Toggle Active/Inactive state of any selected Game object in Unity Hierarchy use Alt + Shift + A. Its working in Unity Version 2018.3.0f2.

There are no shortcuts that I know of. However,
Similar to Customize shortcuts in the unity-editor, you can create a menu item with a shortcut that does this for you.

Create a folder called Editor and inside of it, create a c# script and name it MyShortcuts.cs and paste this in:

using UnityEditor;
using UnityEngine;

public class MyShortcuts : Editor
{
  [MenuItem("GameObject/ActiveToggle _a")]
  static void ToggleActivationSelection()
  {
    var go = Selection.activeGameObject;
    go.SetActive(!go.activeSelf);
  }
}

Now whenever you select an object if you press “a”, it activates/deactivates it. Note that the caps lock should be on. I couldn’t figure out why it needs it to be caps lock, but it does work :slight_smile:

I hope this answers your question.

Thanks for this Aram. A useful modification is to toggle the state of all selected objects, replacing lines 9 and 10 with: foreach(GameObject go in Selection.gameObjects) go.SetActive(!go.activeSelf);

This works brilliantly, thanks a lot! Just a note to others, the Editor folder can just be placed in the Assets folder (there will probably already be one there, there was for me).

When I'm typing text into the Text UI component in Unity the 'A' key gets consumed now and I have to edit this script every time I want to type the letter 'a' somewhere.

@Lohoris2 I‘m not sure, but I guess you can use 3 on the keyboard once you selected an object to toggle the active state. Worked on some previous versions as well

btw guys, broken link: After you've done the above, connect your device with a USB cable to your computer and open a Command Prompt window. Inside the Command Prompt window change the current directory to the directory where your apk is located: http://windows.microsoft.com/en-us/windows/command-prompt-faq#1TC=windows-7 I suggest this http://www.digitalcitizen.life/command-prompt-how-use-basic-commands