diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index fb7dbba1bb..9f7f6b94de 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests. ### Fixed +- Fixed caching for InputControlPath display name. - Fixed the `Auto-Save` toggle button with some extra pixels to align the text in the window better. - Align title font size with toolbar style in `Input Action` window. - Updated Action Properties headers to use colors consistent with GameObject component headers. diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs index cf964d13b8..f5f481b0ab 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs @@ -123,8 +123,22 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert return; } - ////TODO: this should be cached; generates needless GC churn - var displayName = InputControlPath.ToHumanReadableString(path); + // Cache the display name per path value and only recompute when the string actually changes. + if (!string.Equals(path, m_CachedPath, StringComparison.Ordinal)) + { + m_CachedPath = path; + + if (string.IsNullOrEmpty(path)) + { + m_CachedDisplayName = string.Empty; + } + else + { + m_CachedDisplayName = InputControlPath.ToHumanReadableString(path); + } + } + + var displayName = m_CachedDisplayName; // Either show dropdown control that opens path picker or show path directly as // text, if manual path editing is toggled on. @@ -209,6 +223,9 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property) private string m_ExpectedControlLayout; private string[] m_ControlPathsToMatch; + private string m_CachedPath; + private string m_CachedDisplayName; + private InputControlPickerDropdown m_PickerDropdown; private readonly InputControlPickerState m_PickerState;