Add keyboard shortcut for Save Asset

This request has been made by SirIntruder https://discussions.unity.com/t/751511/2 , 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

  1. 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.

7 Likes

Seconded!

Definitely third!

This has been an issue since forever... I remember requesting it in Unity 3.something... :( Fourth

is this still not a thing?

And a Save All graphs button too!

Some auto save functionality would also be nice while you are at it :)

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...

1 Like

Why is this not yet a thing :) Is there some workaround to the missing keyboard shortcut? Some scriptable save mechanism, maybe using reflection?

3 years later... any update?

3 years later still! No hotkey!

1 Like

I feel like this should be an easy task. Please?

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.

    [Shortcut("Save ShaderGraphs", KeyCode.S, ShortcutModifiers.Control | ShortcutModifiers.Shift)]
    public static void SaveShaderGraphs()
    {
        var assembly = AppDomain.CurrentDomain.GetAssemblies()
            .FirstOrDefault(x => x.GetName().Name == "Unity.ShaderGraph.Editor");
        string windowTypeName = "UnityEditor.ShaderGraph.Drawing.MaterialGraphEditWindow";
        var windowType = assembly.GetType(windowTypeName);
        Object[] shaderGraphWindows = Resources.FindObjectsOfTypeAll(windowType);
        if (shaderGraphWindows != null && shaderGraphWindows.Length != 0)
        {
            foreach (var w in shaderGraphWindows)
            {
                var window = w as EditorWindow;
                window.SaveChanges();
            }
        }

        // Also do regular save
        //EditorApplication.ExecuteMenuItem("File/Save");
    }
1 Like