From 8e497fb4e97c7cecc7d14570f81ac3ab51e11a4a Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Mon, 2 Mar 2026 17:37:03 +0100 Subject: [PATCH 1/3] Add progress with bug fix for Editor closing when clicking cancel in a save dialog prompt. --- .../InputActionsEditorWindow.cs | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 41e890533a..b3bf666002 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -24,6 +24,7 @@ static InputActionsEditorWindow() private string m_AssetJson; private bool m_IsDirty; + private bool m_IsEditorQuitting; private StateContainer m_StateContainer; private InputActionsEditorView m_View; @@ -313,11 +314,21 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState) private void OnEnable() { analytics.Begin(); + EditorApplication.wantsToQuit += OnWantsToQuit; } private void OnDisable() { analytics.End(); + EditorApplication.wantsToQuit -= OnWantsToQuit; + } + + private bool OnWantsToQuit() + { + // Here the user will be prompted + bool isAllowedToQuit = OnDestroyIsApplicationAllowedToQuit(false); + m_IsEditorQuitting = isAllowedToQuit; + return m_IsEditorQuitting; } private void OnFocus() @@ -342,39 +353,48 @@ private void OnLostFocus() analytics.RegisterEditorFocusOut(); } - private void HandleOnDestroy() + private bool OnDestroyIsApplicationAllowedToQuit(bool rebuildUIOnCancel) { // Do we have unsaved changes that we need to ask the user to save or discard? if (!m_IsDirty) - return; + return true; // Get target asset path from GUID, if this fails file no longer exists and we need to abort. var assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID); if (string.IsNullOrEmpty(assetPath)) - return; + return true; - // Prompt user with a dialog - var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath); - switch (result) + if (!m_IsEditorQuitting) { - case Dialog.Result.Save: - Save(isAutoSave: false); - break; - case Dialog.Result.Cancel: - // Cancel editor quit. (open new editor window with the edited asset) - ReshowEditorWindowWithUnsavedChanges(); - break; - case Dialog.Result.Discard: - // Don't save, quit - reload the old asset from the json to prevent the asset from being dirtied - break; - default: - throw new ArgumentOutOfRangeException(nameof(result)); + // Prompt user with a dialog + var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath); + switch (result) + { + case Dialog.Result.Save: + Save(isAutoSave: false); + return true; + case Dialog.Result.Cancel: + if (rebuildUIOnCancel) + { + // Cancel editor quit. (open new editor window with the edited asset) + ReshowEditorWindowWithUnsavedChanges(); + } + + return false; + case Dialog.Result.Discard: + // Don't save, quit - reload the old asset from the json to prevent the asset from being dirtied + return true; + default: + throw new ArgumentOutOfRangeException(nameof(result)); + } } + + return true; } private void OnDestroy() { - HandleOnDestroy(); + OnDestroyIsApplicationAllowedToQuit(true); // Clean-up CleanupStateContainer(); From c27e8ca9c03b335f8da88a7463ee6f993602a6b6 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 4 Mar 2026 11:05:58 +0100 Subject: [PATCH 2/3] Update changelog for editor closing fix. --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 71a26a51d7..c15fc036df 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Improved New Input System warning dialog, Native Device Inputs Not Enabled [UUM-132151]. - Fixed caching for InputControlPath display name [ISX-2501](https://jira.unity3d.com/browse/ISX-2501) +- Fixed editor closing and not saving the input asset when clicking cancel in the dialog prompt [UUM-134748](https://jira.unity3d.com/browse/UUM-134748) ### Changed From e0c04bfef041797f243d34ae2f3c3ec74bceab7f Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 4 Mar 2026 11:09:53 +0100 Subject: [PATCH 3/3] Update method signature to better reflect what it does. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index c26a290166..1dfd324660 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -329,7 +329,7 @@ private void OnDisable() private bool OnWantsToQuit() { // Here the user will be prompted - bool isAllowedToQuit = OnDestroyIsApplicationAllowedToQuit(false); + bool isAllowedToQuit = HandleOnDestroyIfApplicationIsAllowedToQuit(false); m_IsEditorQuitting = isAllowedToQuit; return m_IsEditorQuitting; } @@ -356,7 +356,11 @@ private void OnLostFocus() analytics.RegisterEditorFocusOut(); } - private bool OnDestroyIsApplicationAllowedToQuit(bool rebuildUIOnCancel) + /// + /// Shows a dialog when trying to close an input asset without saving changes. + /// + /// Returns true if you should allow the Unity Editor to close. + private bool HandleOnDestroyIfApplicationIsAllowedToQuit(bool rebuildUIOnCancel) { // Do we have unsaved changes that we need to ask the user to save or discard? if (!m_IsDirty) @@ -397,7 +401,7 @@ private bool OnDestroyIsApplicationAllowedToQuit(bool rebuildUIOnCancel) private void OnDestroy() { - OnDestroyIsApplicationAllowedToQuit(true); + HandleOnDestroyIfApplicationIsAllowedToQuit(true); // Clean-up CleanupStateContainer();