From 762b5aa41c8b138b5c2962e036ab0e207646ccef Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Mon, 29 Jan 2024 18:19:57 +0000 Subject: [PATCH 1/5] FIX: Avoid errors logged when opening settings menu (ISX-1721) --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../Editor/UITKAssetEditor/Views/ActionsTreeView.cs | 7 +++++++ .../Editor/UITKAssetEditor/Views/InputActionsEditorView.cs | 7 +++++++ .../InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index c8f9cac971..57717cb68c 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -35,6 +35,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed lingering highlight effect on Save Asset button after clicking. - Fixed missing name in window title for Input Action assets. - Fixed "Listen" functionality for selecting an input sometimes expecting the wrong input type. +- Fixed console errors that can be produced when opening input package settings from the Inspector. ## [1.8.0-pre.2] - 2023-11-09 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs index 3d8b581725..56f4520bac 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs @@ -193,6 +193,13 @@ public override void DestroyView() public override void RedrawUI(ViewState viewState) { + // It's possible for RedrawUI to be called when m_Root is empty, throwing errors in the console. + // This can happen when the view is discarded immediately after being loaded, i.e. jumping to the input settings + // page in Preferences when the last window shown there was the main view, which the editor (briefly) loads first. + // Compare against the number of m_ChildViews as a cheap way to know we should skip redrawing. (ISX-1721) + if (m_Root.childCount != ChildViewCount()) + return; + m_ActionsTreeView.Clear(); m_ActionsTreeView.SetRootItems(viewState.treeViewData); m_ActionsTreeView.Rebuild(); diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs index b6fa07dc77..91d6bb3c37 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs @@ -98,6 +98,13 @@ private void OnAutoSaveToggle(ChangeEvent evt) public override void RedrawUI(ViewState viewState) { + // It's possible for RedrawUI to be called when m_Root is empty, throwing errors in the console. + // This can happen when the view is discarded immediately after being loaded, i.e. jumping to the input settings + // page in Preferences when the last window shown there was the main view, which the editor (briefly) loads first. + // Compare against the number of m_ChildViews as a cheap way to know we should skip redrawing. (ISX-1721) + if (m_Root.childCount != ChildViewCount()) + return; + var toolbarMenu = m_Root.Q("control-schemes-toolbar-menu"); toolbarMenu.menu.MenuItems().Clear(); diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs index 97cb2bbeef..b518973e78 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ViewBase.cs @@ -65,6 +65,11 @@ public void DestroyChildView(TView view) where TView : IView view.DestroyView(); } + public int ChildViewCount() + { + return m_ChildViews.Count; + } + public void Dispatch(Command command) { stateContainer.Dispatch(command); From 4d2c0c64d3d9bc2eb0d23e076ce50265bf4836a7 Mon Sep 17 00:00:00 2001 From: Graham Huws Date: Thu, 1 Feb 2024 10:55:10 +0000 Subject: [PATCH 2/5] Address feedback: Consolidate root element for views and bugfix logic. --- .../UITKAssetEditor/Views/ActionMapsView.cs | 9 ++-- .../Views/ActionPropertiesView.cs | 12 ++--- .../UITKAssetEditor/Views/ActionsTreeView.cs | 23 +++------ .../Views/BindingPropertiesView.cs | 16 +++---- .../Views/CompositeBindingPropertiesView.cs | 8 ++-- .../CompositePartBindingPropertiesView.cs | 6 +-- .../Views/ControlSchemesView.cs | 8 ++-- .../Views/InputActionsEditorView.cs | 48 ++++++++----------- .../Views/NameAndParametersListView.cs | 14 +++--- .../UITKAssetEditor/Views/PropertiesView.cs | 15 +++--- .../Editor/UITKAssetEditor/Views/ViewBase.cs | 18 ++++--- 11 files changed, 72 insertions(+), 105 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs index ae13bced4f..7815762513 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs @@ -13,11 +13,9 @@ namespace UnityEngine.InputSystem.Editor internal class ActionMapsView : ViewBase { public ActionMapsView(VisualElement root, StateContainer stateContainer) - : base(stateContainer) + : base(root, stateContainer) { - m_Root = root; - - m_ListView = m_Root?.Q("action-maps-list-view"); + m_ListView = rootElement?.Q("action-maps-list-view"); m_ListView.selectionType = UIElements.SelectionType.Single; m_ListViewSelectionChangeFilter = new CollectionViewSelectionChangeFilter(m_ListView); @@ -65,7 +63,7 @@ public ActionMapsView(VisualElement root, StateContainer stateContainer) ContextMenu.GetContextMenuForActionMapListView(this, m_ListView.parent); } - private Button addActionMapButton => m_Root?.Q