1
\$\begingroup\$

How do you unselect a game Object in the 3d view using your keyboard?

\$\endgroup\$
2
2
\$\begingroup\$

Reading through the list of Unity editor keyboard shortcuts, it doesn't look like such a shortcut exists.

We can save & load selection presets using Ctrl+(Alt/Shift)+(1-9), but you can't directly save "no selection" into any of these slots. A workaround mentioned in the link Arthur Gibraltar provided is to create a dummy object, save a selection, then delete the dummy object to end up with a saved empty selection.

Instead of this fiddly process, we can add our own Select None shortcut with an editor script placed inside a folder called "Editor":

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;

public static class SelectionHelpers {

    [MenuItem("Selection/Select All (Active Scene) %a")]
    public static void SelectAll() {
        var scene = EditorSceneManager.GetActiveScene();
        var objects = scene.GetRootGameObjects();
        Selection.objects = objects;
    }

    [MenuItem("Selection/Select None %q")]
    public static void SelectNone() {
        Selection.objects = new Object[0];
    }
}

With this script we can Select All with Ctrl+A (or +A on Mac),
and Select None with Ctrl+Q (or +Q)

\$\endgroup\$
2
\$\begingroup\$

Extending from DMGreggory's solution, we could simplify the SelectNone function even more:

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;

public static class SelectionHelpers
{

    [MenuItem("Selection/Select None %q")]
    public static void SelectNone()
    {
        Selection.objects = null;
    }
}

Where the selected objects is being reset to null as opposed to adding an empty object each time we call SelectNone(). This reduces the chances of memory leakage on heap and therefore is a safer solution.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.