Search Unity

Resolved Game View Shortcuts

Discussion in 'Authoring Dev Blitz Day 2023' started by Baste, Jan 25, 2023.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    When the shortcut manager was introduced a few years ago, it came with a big downside - it's impossible to specify that we want global editor shortcuts that are also active when the game view has focus.

    While it's a good default that shortcuts defined in the manager should not be active when playing, there's some instances of shortcuts that we make that I keep trying to hit while playing. The big one is our "clear the console" shortcut - I want to clear the current console content so I'll notice if a new error or warning shows up. I might also want to open specific windows or activate some debug tool in the scene view (on a different monitor).

    Right now all of those require me to click the mouse to give focus to a different part of the editor, then hit the shortcut, then give focus back, which kinda kills the purpose of a keyboard binding in the first place!

    It would be possible to have some kind of in-game singleton that listens for a copy of the shortcut and then does the same thing, but that requires a bunch of annoying engineering to support the same rebind and always be active and only exist in the editor and etc.


    It'd be great if we could specify in ShortcutAttribute that this shortcut should trigger even if the game view has focus.
     
  2. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    Hello @Baste , we have discussed this some time ago and I added your suggestion to our backlog.

    In fact, we do have this functionality for one shortcut ('Window/Capture frame with RenderDoc' - you'll need to install RenderDoc in order to try it) but we need to make it more streamlined before we can expose it.

    I cannot give an exact time frame but I believe we will be able to sneak this feature in before long.
     
    marius-zrelskis and Baste like this.
  3. EricDziurzynski

    EricDziurzynski

    Unity Technologies

    Joined:
    Mar 11, 2022
    Posts:
    53
    @Baste, thank you for the great feedback! We will add this to our insights for updates to the shortcut manager in our backlog so we don't lose sight of this. As Tomas mentioned, we cannot provide an exact timeframe but improvements to the shortcut manager are planned and we will consider this as a feature request for those improvements.
     
  4. Just an idea.

    If you're planning to allow multiple shortcuts to fire in play mode, I would rather go about it this way: instead of litter play mode with pre-defined shortcuts which can fire any time I would make one shortcut (still customizable but on a rare key like shift-~ on PC) which forwards the _next_ shortcut into the editor and fire anything. This way many packages won't force themselves into the play mode keyboard management.

    The problem with the predefined shortcuts firing in play mode is that the asset store packages will go wild with it and soon we will have forced firing editor shortcuts in play mode all the time. Or we turn the whole thing off and end up without them at the same place we're now.
     
    TomasKucinskas likes this.
  5. TomasKucinskas

    TomasKucinskas

    Unity Technologies

    Joined:
    Dec 20, 2017
    Posts:
    60
    @Lurking-Ninja Very good consideration. When doing the RenderDoc shortcut we left it initially unassigned to eliminate unintended execution risk. That probably should be the standard way of defining "Game view shortcuts", otherwise, as you said, we should pick default keys very carefully.

    As for packages, maybe documentation notes on best shortcut binding practices would prevent disruptive package shortcuts?

    Well, in any case, we have recently introduced a button in game view that completely disables Editor shortcuts while in play mode. So you would always have a quick fix for that problem.
     
  6. NippleRider

    NippleRider

    Joined:
    Aug 26, 2014
    Posts:
    3
    Hello folks!

    I've been following all your threads about the shortcuts @Baste (thank you and also thanks to the rest of the team), and I wanted to share a workaround that works for me, in case someone else find it useful.

    Code (CSharp):
    1. using UnityEditor.ShortcutManagement;
    2. using UnityEditor;
    3. using UnityEngine;
    4. using System;
    5.  
    6. public class Test : Singleton<Test>
    7. {
    8.     private const KeyCode KeyCodeP = KeyCode.P;
    9.     private Type _gameViewType;
    10.  
    11.     private void Start()
    12.     {
    13.         _gameViewType = Type.GetType("UnityEditor.GameView,UnityEditor");
    14.     }
    15.  
    16.     [Shortcut("PauseGameShortcut", KeyCodeP, ShortcutModifiers.Shift)]
    17.     public static void PauseGameShortcut()
    18.     {
    19.         Instance.PauseGame();
    20.     }
    21.  
    22.     private void Update()
    23.     {
    24.         if(EditorWindow.focusedWindow != null &&
    25.             EditorWindow.focusedWindow.GetType() == _gameViewType)
    26.         {
    27.             if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
    28.             {
    29.                 if(Input.GetKeyUp(KeyCodeP))
    30.                 {
    31.                     PauseGame();
    32.                 }
    33.             }
    34.         }
    35.     }
    36.  
    37.     private void PauseGame()
    38.     {
    39.         //Pauses the game
    40.     }
    41. }
    The Singleton class I inherit from is a custom one, but it is a regular implementation with nothing special inside

    Cheers!