Skip to content

Commit 55d080e

Browse files
FIX: Implement caching for InputControlPath display name (#2344)
1 parent f5d6714 commit 55d080e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Fixed
1111

1212
- Improved New Input System warning dialog, Native Device Inputs Not Enabled [UUM-132151].
13+
- Fixed caching for InputControlPath display name [ISX-2501](https://jira.unity3d.com/browse/ISX-2501)
1314

1415
### Changed
1516

Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
123123
return;
124124
}
125125

126-
////TODO: this should be cached; generates needless GC churn
127-
var displayName = InputControlPath.ToHumanReadableString(path);
126+
// Cache the display name per path value and only recompute when the string actually changes.
127+
if (!string.Equals(path, m_CachedPath, StringComparison.InvariantCultureIgnoreCase))
128+
{
129+
m_CachedPath = path;
130+
m_CachedDisplayName = InputControlPath.ToHumanReadableString(path);
131+
}
128132

129133
// Either show dropdown control that opens path picker or show path directly as
130134
// text, if manual path editing is toggled on.
@@ -146,7 +150,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
146150
else
147151
{
148152
// Dropdown that shows binding text and allows opening control picker.
149-
if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard))
153+
if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(m_CachedDisplayName), FocusType.Keyboard))
150154
{
151155
SetExpectedControlLayoutFromAttribute(serializedProperty);
152156
////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field
@@ -209,6 +213,9 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property)
209213
private string m_ExpectedControlLayout;
210214
private string[] m_ControlPathsToMatch;
211215

216+
private string m_CachedPath;
217+
private string m_CachedDisplayName;
218+
212219
private InputControlPickerDropdown m_PickerDropdown;
213220
private readonly InputControlPickerState m_PickerState;
214221

0 commit comments

Comments
 (0)