From cd4431d433b516a60d95ce0b994c70e7af253eb4 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Mon, 27 Oct 2025 15:38:29 +0100 Subject: [PATCH 01/13] Add debug state and fix for autosave close UI bug. I still need to look into other solutions / look into if this fix is correct. --- .../InputActionsEditorWindow.cs | 32 +++++++++++++++---- .../Views/ControlSchemesView.cs | 3 ++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 6f08da5045..b06d9ac793 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -188,7 +188,7 @@ private void SetAsset(InputActionAsset asset, string actionToSelect = null, stri m_State = m_State.SelectAction(actionToSelect); } - BuildUI(); + BuildUI(false); } catch (Exception e) { @@ -197,7 +197,9 @@ private void SetAsset(InputActionAsset asset, string actionToSelect = null, stri finally { if (existingWorkingCopy != null) + { DestroyImmediate(existingWorkingCopy); + } } } @@ -259,8 +261,9 @@ private void CleanupStateContainer() } } - private void BuildUI() + private void BuildUI(bool shouldClear = true) { + Debug.LogError("BuildUI: Building asset editor. Error seems to come from here"); CleanupStateContainer(); if (m_State.m_Analytics == null) @@ -269,11 +272,14 @@ private void BuildUI() m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - rootVisualElement.Clear(); + if (shouldClear) + { + rootVisualElement.Clear(); + } + if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); m_View = new InputActionsEditorView(rootVisualElement, m_StateContainer, false, () => Save(isAutoSave: false)); - m_StateContainer.Initialize(rootVisualElement.Q("action-editor")); } @@ -303,6 +309,11 @@ private InputActionAsset GetEditedAsset() private void Save(bool isAutoSave) { + if (isAutoSave) + { + Debug.LogError("Auto-saving input action asset."); + } + var path = AssetDatabase.GUIDToAssetPath(m_AssetGUID); #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS var projectWideActions = InputSystem.actions; @@ -447,8 +458,7 @@ private bool TryUpdateFromAsset() var assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID); if (assetPath == null) { - Debug.LogWarning( - $"Failed to open InputActionAsset with GUID {m_AssetGUID}. The asset might have been deleted."); + Debug.LogWarning($"Failed to open InputActionAsset with GUID {m_AssetGUID}. The asset might have been deleted."); return false; } @@ -458,7 +468,9 @@ private bool TryUpdateFromAsset() var asset = AssetDatabase.LoadAssetAtPath(assetPath); workingCopy = InputActionAssetManager.CreateWorkingCopy(asset); m_AssetJson = InputActionsEditorWindowUtils.ToJsonWithoutName(asset); + m_State = new InputActionsEditorState(m_State, new SerializedObject(workingCopy)); + //TODO THIS CAUSES THE ERROR m_IsDirty = false; } catch (Exception e) @@ -501,17 +513,25 @@ public void OnAssetImported() // is not much we can do about it but to ignore loading the changes. If the editors asset is // unmodified, we can refresh the editor with the latest content from disc. if (m_IsDirty) + { + Debug.LogError("Return in OnAssetImported"); return; + } + + Debug.LogError("OnAssetImported"); // If our asset has disappeared from disk, just close the window. var assetPath = AssetDatabase.GUIDToAssetPath(assetGUID); if (string.IsNullOrEmpty(assetPath)) { m_IsDirty = false; // Avoid checks + Debug.LogError("OnAssetImported CLOSE CALLED!!"); + Close(); return; } + Debug.LogError("OnAssetImported CLoadAssetAtPath!!"); SetAsset(AssetDatabase.LoadAssetAtPath(assetPath)); } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs index e6e7e58e5f..08df34f568 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs @@ -118,6 +118,8 @@ public override void RedrawUI(InputControlScheme viewState) public override void DestroyView() { + Debug.LogError("Destroying view! "); + m_ModalWindow.RemoveFromHierarchy(); } @@ -145,6 +147,7 @@ private void CloseView() // the changes retained. However, if a different ControlScheme is selected or the Asset // Editor window is closed, then the changes are lost. + Debug.LogError("Closing the control scheme view here"); m_NewName = string.Empty; OnClosing?.Invoke(this); } From 580fd656058c016c4150f6d9069a7b7a93d92adb Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 28 Oct 2025 16:43:35 +0100 Subject: [PATCH 02/13] Add small refactor and remove debug log error's. --- .../InputActionsEditorWindow.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index b06d9ac793..32246f9ca7 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -167,7 +167,7 @@ private static GUIContent GetEditorTitle(InputActionAsset asset, bool isDirty) return new GUIContent(text); } - private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null) + private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null, bool shouldClearRootVisualElement = true) { var existingWorkingCopy = m_AssetObjectForEditing; @@ -188,7 +188,7 @@ private void SetAsset(InputActionAsset asset, string actionToSelect = null, stri m_State = m_State.SelectAction(actionToSelect); } - BuildUI(false); + BuildUI(shouldClearRootVisualElement); } catch (Exception e) { @@ -261,9 +261,8 @@ private void CleanupStateContainer() } } - private void BuildUI(bool shouldClear = true) + private void BuildUI(bool shouldClearRoot = true) { - Debug.LogError("BuildUI: Building asset editor. Error seems to come from here"); CleanupStateContainer(); if (m_State.m_Analytics == null) @@ -272,7 +271,7 @@ private void BuildUI(bool shouldClear = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - if (shouldClear) + if (shouldClearRoot) { rootVisualElement.Clear(); } @@ -514,25 +513,20 @@ public void OnAssetImported() // unmodified, we can refresh the editor with the latest content from disc. if (m_IsDirty) { - Debug.LogError("Return in OnAssetImported"); return; } - Debug.LogError("OnAssetImported"); - // If our asset has disappeared from disk, just close the window. var assetPath = AssetDatabase.GUIDToAssetPath(assetGUID); if (string.IsNullOrEmpty(assetPath)) { m_IsDirty = false; // Avoid checks - Debug.LogError("OnAssetImported CLOSE CALLED!!"); - Close(); return; } - Debug.LogError("OnAssetImported CLoadAssetAtPath!!"); - SetAsset(AssetDatabase.LoadAssetAtPath(assetPath)); + // We set shouldClearRootVisualElement to false here as we don't want the root visual element's child elements to be closed during an auto save. + SetAsset(AssetDatabase.LoadAssetAtPath(assetPath), shouldClearRootVisualElement: false); } #endregion From dae767641f2e610906d33adb76e057d5636b39e6 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 28 Oct 2025 16:55:03 +0100 Subject: [PATCH 03/13] Tidy up for code review. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 7 ------- .../Editor/UITKAssetEditor/Views/ControlSchemesView.cs | 3 --- 2 files changed, 10 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 32246f9ca7..4628bb3a4d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -308,11 +308,6 @@ private InputActionAsset GetEditedAsset() private void Save(bool isAutoSave) { - if (isAutoSave) - { - Debug.LogError("Auto-saving input action asset."); - } - var path = AssetDatabase.GUIDToAssetPath(m_AssetGUID); #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS var projectWideActions = InputSystem.actions; @@ -467,9 +462,7 @@ private bool TryUpdateFromAsset() var asset = AssetDatabase.LoadAssetAtPath(assetPath); workingCopy = InputActionAssetManager.CreateWorkingCopy(asset); m_AssetJson = InputActionsEditorWindowUtils.ToJsonWithoutName(asset); - m_State = new InputActionsEditorState(m_State, new SerializedObject(workingCopy)); - //TODO THIS CAUSES THE ERROR m_IsDirty = false; } catch (Exception e) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs index 08df34f568..e6e7e58e5f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs @@ -118,8 +118,6 @@ public override void RedrawUI(InputControlScheme viewState) public override void DestroyView() { - Debug.LogError("Destroying view! "); - m_ModalWindow.RemoveFromHierarchy(); } @@ -147,7 +145,6 @@ private void CloseView() // the changes retained. However, if a different ControlScheme is selected or the Asset // Editor window is closed, then the changes are lost. - Debug.LogError("Closing the control scheme view here"); m_NewName = string.Empty; OnClosing?.Invoke(this); } From 95fdd49c13ad6ea12282eed745882c78cbc22440 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Tue, 28 Oct 2025 18:12:29 +0100 Subject: [PATCH 04/13] Remove added braces. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 4628bb3a4d..3e1ff512d1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -505,9 +505,7 @@ public void OnAssetImported() // is not much we can do about it but to ignore loading the changes. If the editors asset is // unmodified, we can refresh the editor with the latest content from disc. if (m_IsDirty) - { return; - } // If our asset has disappeared from disk, just close the window. var assetPath = AssetDatabase.GUIDToAssetPath(assetGUID); From caa7c8432d7bf5768393044431d0e9971c7e18ca Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 09:05:27 +0100 Subject: [PATCH 05/13] Test commit to see if this fixes tests. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 3e1ff512d1..a7e074d1fe 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,10 +271,10 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - if (shouldClearRoot) - { - rootVisualElement.Clear(); - } + //if (shouldClearRoot) + //{ + rootVisualElement.Clear(); + //} if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); From 3b64031903938d743bd0df834f81924493943251 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 11:02:56 +0100 Subject: [PATCH 06/13] re-enable fix to see if tests pass. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index a7e074d1fe..3e1ff512d1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,10 +271,10 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - //if (shouldClearRoot) - //{ - rootVisualElement.Clear(); - //} + if (shouldClearRoot) + { + rootVisualElement.Clear(); + } if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); From b955c318cf7ad55f2224f9cc493b7cbd3c0d5aaa Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 11:37:34 +0100 Subject: [PATCH 07/13] Remove fix to compare tests again. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 3e1ff512d1..90f1fb7d6e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,10 +271,7 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - if (shouldClearRoot) - { - rootVisualElement.Clear(); - } + rootVisualElement.Clear(); if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); From 2ec6cb12dec1dcc111b1fa72be9be1233021bb63 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 12:33:45 +0100 Subject: [PATCH 08/13] Add exception to code path to see if we are using this flow for tests. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 90f1fb7d6e..13dd80eab8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,6 +271,11 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; + if (shouldClearRoot == false) + { + throw new Exception("We are calling BuildUI with shouldClearRoot in a test!!!!"); + } + rootVisualElement.Clear(); if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) From b10ef77d8d0af7cc54d629cea3b673c855bae87d Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 15:58:38 +0100 Subject: [PATCH 09/13] Remove exception log. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 13dd80eab8..90f1fb7d6e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,11 +271,6 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - if (shouldClearRoot == false) - { - throw new Exception("We are calling BuildUI with shouldClearRoot in a test!!!!"); - } - rootVisualElement.Clear(); if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) From 506895687b6da63221429b7dca0a3797fbc944e7 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 16:45:00 +0100 Subject: [PATCH 10/13] Add fix back in. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 90f1fb7d6e..3e1ff512d1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -271,7 +271,10 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - rootVisualElement.Clear(); + if (shouldClearRoot) + { + rootVisualElement.Clear(); + } if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); From e8ed4857eecc7965a5ea74cde01017e5da5d793f Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Wed, 29 Oct 2025 16:50:43 +0100 Subject: [PATCH 11/13] Add hacky test fix to see if CI passes. --- .../InputActionsEditorWindow.cs | 23 ++++++++++++++++--- 1 file changed, 20 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 3e1ff512d1..86657fa72c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -2,6 +2,7 @@ // Therefore the UITK version of the InputActionAsset Editor is not available on earlier Editor versions either. #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS using System; +using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEditor.Callbacks; @@ -270,16 +271,32 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - - if (shouldClearRoot) + IEnumerable children = null; + if (!shouldClearRoot) { - rootVisualElement.Clear(); + children = new List(rootVisualElement.hierarchy.Children()); } + rootVisualElement.Clear(); + if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); m_View = new InputActionsEditorView(rootVisualElement, m_StateContainer, false, () => Save(isAutoSave: false)); m_StateContainer.Initialize(rootVisualElement.Q("action-editor")); + + if (children != null) + { + foreach (var child in children) + { + for (int i = rootVisualElement.hierarchy.childCount - 1; i >= 0; i--) + { + if (rootVisualElement.hierarchy.ElementAt(i).name != child.name) + { + rootVisualElement.hierarchy.Add(child); + } + } + } + } } private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode) From 7b435644f4e6bcdd63faa3de4d815dd808127d80 Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 30 Oct 2025 12:50:20 +0100 Subject: [PATCH 12/13] Add better fix for the control schemes view closing on autosave. We now just don't autosave in this case as there is no need. --- .../InputActionsEditorWindow.cs | 29 ++++--------------- .../Views/ControlSchemesView.cs | 10 +++++++ 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs index 86657fa72c..8f1cc1ca3d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -168,7 +168,7 @@ private static GUIContent GetEditorTitle(InputActionAsset asset, bool isDirty) return new GUIContent(text); } - private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null, bool shouldClearRootVisualElement = true) + private void SetAsset(InputActionAsset asset, string actionToSelect = null, string actionMapToSelect = null) { var existingWorkingCopy = m_AssetObjectForEditing; @@ -189,7 +189,7 @@ private void SetAsset(InputActionAsset asset, string actionToSelect = null, stri m_State = m_State.SelectAction(actionToSelect); } - BuildUI(shouldClearRootVisualElement); + BuildUI(); } catch (Exception e) { @@ -262,7 +262,7 @@ private void CleanupStateContainer() } } - private void BuildUI(bool shouldClearRoot = true) + private void BuildUI() { CleanupStateContainer(); @@ -271,11 +271,6 @@ private void BuildUI(bool shouldClearRoot = true) m_StateContainer = new StateContainer(m_State, m_AssetGUID); m_StateContainer.StateChanged += OnStateChanged; - IEnumerable children = null; - if (!shouldClearRoot) - { - children = new List(rootVisualElement.hierarchy.Children()); - } rootVisualElement.Clear(); @@ -283,20 +278,6 @@ private void BuildUI(bool shouldClearRoot = true) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); m_View = new InputActionsEditorView(rootVisualElement, m_StateContainer, false, () => Save(isAutoSave: false)); m_StateContainer.Initialize(rootVisualElement.Q("action-editor")); - - if (children != null) - { - foreach (var child in children) - { - for (int i = rootVisualElement.hierarchy.childCount - 1; i >= 0; i--) - { - if (rootVisualElement.hierarchy.ElementAt(i).name != child.name) - { - rootVisualElement.hierarchy.Add(child); - } - } - } - } } private void OnStateChanged(InputActionsEditorState newState, UIRebuildMode editorRebuildMode) @@ -388,7 +369,7 @@ private void OnLostFocus() // This code should be cleaned up once we migrate the InputControl stuff from ImGUI completely. // Since at that point it stops being a separate window that steals focus. // (See case ISXB-1221) - if (!InputControlPathEditor.IsShowingDropdown) + if (!InputControlPathEditor.IsShowingDropdown && !ControlSchemesView.IsShowingControlSchemeView) Save(isAutoSave: true); #endif @@ -534,7 +515,7 @@ public void OnAssetImported() } // We set shouldClearRootVisualElement to false here as we don't want the root visual element's child elements to be closed during an auto save. - SetAsset(AssetDatabase.LoadAssetAtPath(assetPath), shouldClearRootVisualElement: false); + SetAsset(AssetDatabase.LoadAssetAtPath(assetPath)); } #endregion diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs index e6e7e58e5f..ce83b6d743 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs @@ -14,9 +14,16 @@ internal class ControlSchemesView : ViewBase private string m_NewName; public event Action> OnClosing; + /// + /// This property is only set from this class in order to communicate that we're showing the control schemes view at the moment + /// It's employed to skip auto-saving, because that complicates the save causing this window to close when adding a new device type. + /// + internal static bool IsShowingControlSchemeView { get; private set; } + public ControlSchemesView(VisualElement root, StateContainer stateContainer, bool updateExisting = false) : base(root, stateContainer) { + IsShowingControlSchemeView = true; m_UpdateExisting = updateExisting; var controlSchemeEditor = AssetDatabase.LoadAssetAtPath( @@ -118,6 +125,7 @@ public override void RedrawUI(InputControlScheme viewState) public override void DestroyView() { + IsShowingControlSchemeView = false; m_ModalWindow.RemoveFromHierarchy(); } @@ -137,6 +145,8 @@ private void Cancel() private void CloseView() { + IsShowingControlSchemeView = false; + // Closing the View without explicitly selecting "Save" or "Cancel" holds the values in the // current UI state but won't persist them; the Asset Editor state isn't dirtied. // From 1c4fa6de850510da965f922213946b1c8d4302bb Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 30 Oct 2025 12:54:10 +0100 Subject: [PATCH 13/13] Add final cleanup for code review. --- .../Editor/UITKAssetEditor/InputActionsEditorWindow.cs | 3 --- 1 file changed, 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 8f1cc1ca3d..667cbf7aa5 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs @@ -2,7 +2,6 @@ // Therefore the UITK version of the InputActionAsset Editor is not available on earlier Editor versions either. #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS using System; -using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEditor.Callbacks; @@ -273,7 +272,6 @@ private void BuildUI() m_StateContainer.StateChanged += OnStateChanged; rootVisualElement.Clear(); - if (!rootVisualElement.styleSheets.Contains(InputActionsEditorWindowUtils.theme)) rootVisualElement.styleSheets.Add(InputActionsEditorWindowUtils.theme); m_View = new InputActionsEditorView(rootVisualElement, m_StateContainer, false, () => Save(isAutoSave: false)); @@ -514,7 +512,6 @@ public void OnAssetImported() return; } - // We set shouldClearRootVisualElement to false here as we don't want the root visual element's child elements to be closed during an auto save. SetAsset(AssetDatabase.LoadAssetAtPath(assetPath)); }