Skip to content

Commit 0f3413d

Browse files
authored
FIX: All InputControls change when modifying one (#2199)
1 parent e399779 commit 0f3413d

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ however, it has to be formatted properly to pass verification tests.
3131
- Fixed the TreeView compilation warnings when used with Unity 6.2 beta (ISX-2320)
3232
- Fixed actions being reset when disabling the InputSystemUIInputModule component [ISXB-1493](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1493)
3333
- Fixed a memory leak when disabling and enabling the InputSystemUIInputModule component at runtime [ISXB-1573](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1573)
34+
- Fixed all InputControls being changed at once when you change just one by reverting `2a37caac288ac09bc9122234339dc5df8d3a0ca6`, which was an attempt at fixing [ISXB-1221] that introduced this regression [ISXB-1531] (https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1493)
3435
- Fixed PlayerInput component automatically switching away from the default ActionMap set to 'None'.
3536
- Fixed a console error being shown when targeting visionOS builds in 2022.3.
3637
- Fixed a Tap Interaction issue with analog controls. The Tap interaction would keep re-starting after timeout. [ISXB-627](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-627)

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ public InputControlPathEditor(SerializedProperty pathProperty, InputControlPicke
3030
{
3131
if (pathProperty == null)
3232
throw new ArgumentNullException(nameof(pathProperty));
33-
// Update the static pathProperty variable to the most recent serializedProperty.
34-
// See comment on pathProperty for more information.
35-
s_pathProperty = pathProperty;
33+
34+
this.pathProperty = pathProperty;
3635
this.onModified = onModified;
3736
m_PickerState = pickerState ?? new InputControlPickerState();
3837
m_PathLabel = label ?? new GUIContent(pathProperty.displayName, pathProperty.GetTooltip());
3938
}
4039

4140
public void Dispose()
4241
{
43-
s_pathProperty = null;
4442
m_PickerDropdown?.Dispose();
4543
}
4644

@@ -91,10 +89,10 @@ public void OnGUI()
9189
EditorGUILayout.EndHorizontal();
9290
}
9391

94-
//TODO: on next major version remove property argument.
9592
public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty property = null, Action modifiedCallback = null)
9693
{
9794
var pathLabel = label ?? m_PathLabel;
95+
var serializedProperty = property ?? pathProperty;
9896

9997
var lineRect = rect;
10098
var labelRect = lineRect;
@@ -115,7 +113,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
115113
var path = String.Empty;
116114
try
117115
{
118-
path = pathProperty.stringValue;
116+
path = serializedProperty.stringValue;
119117
}
120118
catch
121119
{
@@ -140,8 +138,8 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
140138
path = EditorGUI.DelayedTextField(bindingTextRect, path);
141139
if (EditorGUI.EndChangeCheck())
142140
{
143-
pathProperty.stringValue = path;
144-
pathProperty.serializedObject.ApplyModifiedProperties();
141+
serializedProperty.stringValue = path;
142+
serializedProperty.serializedObject.ApplyModifiedProperties();
145143
(modifiedCallback ?? onModified).Invoke();
146144
}
147145
}
@@ -150,9 +148,9 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
150148
// Dropdown that shows binding text and allows opening control picker.
151149
if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard))
152150
{
153-
SetExpectedControlLayoutFromAttribute(pathProperty);
151+
SetExpectedControlLayoutFromAttribute(serializedProperty);
154152
////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field
155-
ShowDropdown(bindingTextRect, modifiedCallback ?? onModified);
153+
ShowDropdown(bindingTextRect, serializedProperty, modifiedCallback ?? onModified);
156154
}
157155
}
158156

@@ -161,7 +159,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
161159
EditorStyles.miniButton);
162160
}
163161

164-
private void ShowDropdown(Rect rect, Action modifiedCallback)
162+
private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Action modifiedCallback)
165163
{
166164
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
167165
InputActionsEditorSettingsProvider.SetIMGUIDropdownVisible(true, false);
@@ -172,13 +170,19 @@ private void ShowDropdown(Rect rect, Action modifiedCallback)
172170
m_PickerState,
173171
path =>
174172
{
175-
pathProperty.stringValue = path;
176-
pathProperty.serializedObject.ApplyModifiedProperties();
173+
serializedProperty.stringValue = path;
177174
m_PickerState.manualPathEditMode = false;
178175
modifiedCallback();
179176
});
180177
}
181178

179+
m_PickerDropdown.SetPickedCallback(path =>
180+
{
181+
serializedProperty.stringValue = path;
182+
m_PickerState.manualPathEditMode = false;
183+
modifiedCallback();
184+
});
185+
182186
m_PickerDropdown.SetControlPathsToMatch(m_ControlPathsToMatch);
183187
m_PickerDropdown.SetExpectedControlLayout(m_ExpectedControlLayout);
184188

@@ -196,16 +200,7 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property)
196200
SetExpectedControlLayout(attribute.layout);
197201
}
198202

199-
// This static variable is a hack. Because the editor is rebuilt at unpredictable times with a new serializedObject, we need to keep updating
200-
// this variable with most up to date serializedProperty, so that the picker dropdown can access the correct serializedProperty.
201-
// The picker dropdown is a separate window and does not have access to the changed serializedObject reference.
202-
// This could be removed if the InputControlPathEditor is converted to UITK with a stable, persistent serializedObject backing this editor.
203-
// This property will be shared among multiple asset editor windows.
204-
private static SerializedProperty s_pathProperty { get; set; }
205-
206-
// This property will always return the most recent serializedProperty.
207-
public SerializedProperty pathProperty { get => s_pathProperty;}
208-
203+
public SerializedProperty pathProperty { get; }
209204
public Action onModified { get; }
210205

211206
private GUIContent m_PathLabel;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public void SetExpectedControlLayout(string expectedControlLayout)
5858
Reload();
5959
}
6060

61+
public void SetPickedCallback(Action<string> action)
62+
{
63+
m_OnPickCallback = action;
64+
}
65+
6166
protected override void OnDestroy()
6267
{
6368
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS

Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputControlPathDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
4444
}
4545

4646
EditorGUI.BeginProperty(position, label, property);
47-
m_Editor.OnGUI(position, label, property: null, modifiedCallback: () => property.serializedObject.ApplyModifiedProperties());
47+
m_Editor.OnGUI(position, label, property, () => property.serializedObject.ApplyModifiedProperties());
4848
EditorGUI.EndProperty();
4949
}
5050
}

0 commit comments

Comments
 (0)