Skip to content

Commit 2a37caa

Browse files
authored
FIX: ISXB-1221 input action binding discarded (#2119)
1 parent 14bb2d5 commit 2a37caa

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
2424
- Fixed an issue causing InvalidOperationException when entering playmode with domain reload disabled. [ISXB-1208](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1208).
2525
- Fixed an issue where compiling Addressables with Input System package present would result in failed compilation due to `IInputAnalytic.TryGatherData` not being defined [ISXB-1203](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1203).
2626
- Pinned Touch Samples sample package dependencies to avoid errors with Cinemachine 3.x and Probuilder 6.x. [ISXB-1245](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1245)
27+
- Fixed issue where a binding path is sometimes not saved when chosen from the binding path picker. [ISXB-1221](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1221)
2728
- Fixed an issue where dropdown menu for Path in Input Actions Editor could not be selected from any button position. [ISXB-1309](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1309)
2829

2930
## [1.12.0] - 2025-01-15

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

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

4041
public void Dispose()
4142
{
43+
s_pathProperty = null;
4244
m_PickerDropdown?.Dispose();
4345
}
4446

@@ -89,10 +91,10 @@ public void OnGUI()
8991
EditorGUILayout.EndHorizontal();
9092
}
9193

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

9799
var lineRect = rect;
98100
var labelRect = lineRect;
@@ -113,7 +115,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
113115
var path = String.Empty;
114116
try
115117
{
116-
path = serializedProperty.stringValue;
118+
path = pathProperty.stringValue;
117119
}
118120
catch
119121
{
@@ -138,8 +140,8 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
138140
path = EditorGUI.DelayedTextField(bindingTextRect, path);
139141
if (EditorGUI.EndChangeCheck())
140142
{
141-
serializedProperty.stringValue = path;
142-
serializedProperty.serializedObject.ApplyModifiedProperties();
143+
pathProperty.stringValue = path;
144+
pathProperty.serializedObject.ApplyModifiedProperties();
143145
(modifiedCallback ?? onModified).Invoke();
144146
}
145147
}
@@ -148,9 +150,9 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert
148150
// Dropdown that shows binding text and allows opening control picker.
149151
if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard))
150152
{
151-
SetExpectedControlLayoutFromAttribute(serializedProperty);
153+
SetExpectedControlLayoutFromAttribute(pathProperty);
152154
////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field
153-
ShowDropdown(bindingTextRect, serializedProperty, modifiedCallback ?? onModified);
155+
ShowDropdown(bindingTextRect, modifiedCallback ?? onModified);
154156
}
155157
}
156158

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

162-
private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Action modifiedCallback)
164+
private void ShowDropdown(Rect rect, Action modifiedCallback)
163165
{
164166
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
165167
InputActionsEditorSettingsProvider.SetIMGUIDropdownVisible(true, false);
@@ -170,19 +172,13 @@ private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Acti
170172
m_PickerState,
171173
path =>
172174
{
173-
serializedProperty.stringValue = path;
175+
pathProperty.stringValue = path;
176+
pathProperty.serializedObject.ApplyModifiedProperties();
174177
m_PickerState.manualPathEditMode = false;
175178
modifiedCallback();
176179
});
177180
}
178181

179-
m_PickerDropdown.SetPickedCallback(path =>
180-
{
181-
serializedProperty.stringValue = path;
182-
m_PickerState.manualPathEditMode = false;
183-
modifiedCallback();
184-
});
185-
186182
m_PickerDropdown.SetControlPathsToMatch(m_ControlPathsToMatch);
187183
m_PickerDropdown.SetExpectedControlLayout(m_ExpectedControlLayout);
188184

@@ -200,7 +196,16 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property)
200196
SetExpectedControlLayout(attribute.layout);
201197
}
202198

203-
public SerializedProperty pathProperty { get; }
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+
204209
public Action onModified { get; }
205210

206211
private GUIContent m_PathLabel;

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

-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public void SetExpectedControlLayout(string expectedControlLayout)
5858
Reload();
5959
}
6060

61-
public void SetPickedCallback(Action<string> action)
62-
{
63-
m_OnPickCallback = action;
64-
}
65-
6661
protected override void OnDestroy()
6762
{
6863
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS

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

+1-1
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, () => property.serializedObject.ApplyModifiedProperties());
47+
m_Editor.OnGUI(position, label, property: null, modifiedCallback: () => property.serializedObject.ApplyModifiedProperties());
4848
EditorGUI.EndProperty();
4949
}
5050
}

0 commit comments

Comments
 (0)