Search Unity

Feature Request Add keyboard shortcut for Save Asset

Discussion in 'Shader Graph' started by huulong, Dec 7, 2019.

  1. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    This request has been made by SirIntruder https://forum.unity.com/threads/ux-...with-color-gradient-node.714512/#post-4773080, but it was a double-post therefore the thread title doesn't match the 2nd request, and I'm re-posting it properly here.

    When editing a shader, I sometimes have the impression I saved it, only to realize I'm still viewing the old shader in the game scene. This is because Ctrl+S is still mapped to File > Save (scene) when using the Shader Graph.

    For now, the only way to actually save the shader is to click Save Asset. A shortcut would make it easier to test the changes in the actual scene quickly (whether the user switches to the Scene tab, or split window between Scene and Shader Graph).

    I suggest the following:

    1a. When the Shader Graph tab is focused, Ctrl+S contextually remaps to Save Asset.
    This is the most intuitive, but there is a possible ambiguity with Save scene in case the user is using split window and didn't notice he/she was focusing Shader Graph rather than Scene tab. So the editor must feedback to the user that the shader was saved indeed, not the scene.

    or

    1b. Another shortcut, such as Ctrl+Alt+Shift+S, will Save Asset on the currently focused Shader Graph, if any. I prefer 1a to this solution due to the complexity of the shortcut compared to clicking on a button, but see Customization below.

    and

    2. An option to Save Asset automatically every X seconds (if any change detected), to avoid heavy processing while still being able to see the result in the Scene. Probably less convenient, though, it's more a backup idea to me.

    About Customization:

    I tried Edit > Shortcuts... to customize the Save Asset shortcut, but it seems it only works with top-bar menu items (and maybe even native Unity items, not items added by packages?). So Save Asset would have to be a menu item (rather than a button inside the tab), and the Shortcuts menu would have to support package/custom script menu items to allow us to customize the Save Asset shortcut.

    But to me, it would be the best as I guess some users would prefer a simpler shortcut (e.g. Ctrl+Alt+S is used for Version Control/Submit Changeset ... but I don't use Version Control so I could use this one instead). However, if they want to use Ctrl+S it will conflict with the existing Save (scene), and I don't think Unity can prioritize custom shortcuts like that (some code editors like Atom or Visual Studio allow you to define the context of a shortcut, but Unity doesn't), so some hardcoded work may still be needed in the end.

    Alternatively, there could be a Settings window just for the Shader Editor where you would customize the save shortcut. I'd rather have everything centralized though.

    I think in Unreal, I was using Ctrl+S in the Material Editor it would save my changes and saving is contextual in that editor.
     
    GDevTeam, kidapu-w, NotaNaN and 4 others like this.
  2. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Seconded!
     
  3. Deleted User

    Deleted User

    Guest

    Definitely third!
     
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    This has been an issue since forever... I remember requesting it in Unity 3.something... :( Fourth
     
  5. troxmo

    troxmo

    Joined:
    Mar 16, 2022
    Posts:
    1
    is this still not a thing?
     
  6. OmniShader

    OmniShader

    Joined:
    Feb 12, 2022
    Posts:
    44
    And a Save All graphs button too!
     
  7. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    53
    Some auto save functionality would also be nice while you are at it :)
     
  8. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Three years to get a shortcut for something as basic as save functionality is a bit frustrating. Is there a feature request for this anywhere? I agree that I often find myself pressing Ctrl+S thinking the shader saved only to realize a while late that it didn't. It seems quite broken the way it is...
     
    david-wtf likes this.
  9. david-wtf

    david-wtf

    Joined:
    Sep 30, 2021
    Posts:
    25
    Why is this not yet a thing :) Is there some workaround to the missing keyboard shortcut? Some scriptable save mechanism, maybe using reflection?
     
  10. Infinite-3D

    Infinite-3D

    Joined:
    Jan 5, 2020
    Posts:
    40
    3 years later... any update?
     
  11. BionicWombatGames

    BionicWombatGames

    Joined:
    Oct 5, 2020
    Posts:
    33
    3 years later still! No hotkey!
     
    GDevTeam likes this.
  12. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    258
    I feel like this should be an easy task. Please?
     
  13. Epsilon_Delta

    Epsilon_Delta

    Joined:
    Mar 14, 2018
    Posts:
    258
    Okay so I put together some editor code to alleviate the pain until this is resolved by Unity. Following code saves all open ShaderGraph tabs (even those that are not visible/in the front of dock area). It can be changed easily to save only focused editor window.

    Code (CSharp):
    1.     [Shortcut("Save ShaderGraphs", KeyCode.S, ShortcutModifiers.Control | ShortcutModifiers.Shift)]
    2.     public static void SaveShaderGraphs()
    3.     {
    4.         var assembly = AppDomain.CurrentDomain.GetAssemblies()
    5.             .FirstOrDefault(x => x.GetName().Name == "Unity.ShaderGraph.Editor");
    6.         string windowTypeName = "UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow";
    7.         var windowType = assembly.GetType(windowTypeName);
    8.         Object[] shaderGraphWindows = Resources.FindObjectsOfTypeAll(windowType);
    9.         if (shaderGraphWindows != null && shaderGraphWindows.Length != 0)
    10.         {
    11.             foreach (var w in shaderGraphWindows)
    12.             {
    13.                 var window = w as EditorWindow;
    14.                 window.SaveChanges();
    15.             }
    16.         }
    17.  
    18.         // Also do regular save
    19.         //EditorApplication.ExecuteMenuItem("File/Save");
    20.     }
     
    david-wtf likes this.