diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 600d71c5f3..264e343bad 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed an issue causing InvalidOperationException when entering playmode with domain reload disabled. [ISXB-1208](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1208). - 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). - 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) +- 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) - 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) ## [1.12.0] - 2025-01-15 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs index 91d10fdc81..4ffc09886c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPathEditor.cs @@ -30,8 +30,9 @@ public InputControlPathEditor(SerializedProperty pathProperty, InputControlPicke { if (pathProperty == null) throw new ArgumentNullException(nameof(pathProperty)); - - this.pathProperty = pathProperty; + // Update the static pathProperty variable to the most recent serializedProperty. + // See comment on pathProperty for more information. + s_pathProperty = pathProperty; this.onModified = onModified; m_PickerState = pickerState ?? new InputControlPickerState(); m_PathLabel = label ?? new GUIContent(pathProperty.displayName, pathProperty.GetTooltip()); @@ -39,6 +40,7 @@ public InputControlPathEditor(SerializedProperty pathProperty, InputControlPicke public void Dispose() { + s_pathProperty = null; m_PickerDropdown?.Dispose(); } @@ -89,10 +91,10 @@ public void OnGUI() EditorGUILayout.EndHorizontal(); } + //TODO: on next major version remove property argument. public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty property = null, Action modifiedCallback = null) { var pathLabel = label ?? m_PathLabel; - var serializedProperty = property ?? pathProperty; var lineRect = rect; var labelRect = lineRect; @@ -113,7 +115,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert var path = String.Empty; try { - path = serializedProperty.stringValue; + path = pathProperty.stringValue; } catch { @@ -138,8 +140,8 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert path = EditorGUI.DelayedTextField(bindingTextRect, path); if (EditorGUI.EndChangeCheck()) { - serializedProperty.stringValue = path; - serializedProperty.serializedObject.ApplyModifiedProperties(); + pathProperty.stringValue = path; + pathProperty.serializedObject.ApplyModifiedProperties(); (modifiedCallback ?? onModified).Invoke(); } } @@ -148,9 +150,9 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert // Dropdown that shows binding text and allows opening control picker. if (EditorGUI.DropdownButton(bindingTextRect, new GUIContent(displayName), FocusType.Keyboard)) { - SetExpectedControlLayoutFromAttribute(serializedProperty); + SetExpectedControlLayoutFromAttribute(pathProperty); ////TODO: for bindings that are part of composites, use the layout information from the [InputControl] attribute on the field - ShowDropdown(bindingTextRect, serializedProperty, modifiedCallback ?? onModified); + ShowDropdown(bindingTextRect, modifiedCallback ?? onModified); } } @@ -159,7 +161,7 @@ public void OnGUI(Rect rect, GUIContent label = null, SerializedProperty propert EditorStyles.miniButton); } - private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Action modifiedCallback) + private void ShowDropdown(Rect rect, Action modifiedCallback) { #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS InputActionsEditorSettingsProvider.SetIMGUIDropdownVisible(true, false); @@ -170,19 +172,13 @@ private void ShowDropdown(Rect rect, SerializedProperty serializedProperty, Acti m_PickerState, path => { - serializedProperty.stringValue = path; + pathProperty.stringValue = path; + pathProperty.serializedObject.ApplyModifiedProperties(); m_PickerState.manualPathEditMode = false; modifiedCallback(); }); } - m_PickerDropdown.SetPickedCallback(path => - { - serializedProperty.stringValue = path; - m_PickerState.manualPathEditMode = false; - modifiedCallback(); - }); - m_PickerDropdown.SetControlPathsToMatch(m_ControlPathsToMatch); m_PickerDropdown.SetExpectedControlLayout(m_ExpectedControlLayout); @@ -200,7 +196,16 @@ private void SetExpectedControlLayoutFromAttribute(SerializedProperty property) SetExpectedControlLayout(attribute.layout); } - public SerializedProperty pathProperty { get; } + // This static variable is a hack. Because the editor is rebuilt at unpredictable times with a new serializedObject, we need to keep updating + // this variable with most up to date serializedProperty, so that the picker dropdown can access the correct serializedProperty. + // The picker dropdown is a separate window and does not have access to the changed serializedObject reference. + // This could be removed if the InputControlPathEditor is converted to UITK with a stable, persistent serializedObject backing this editor. + // This property will be shared among multiple asset editor windows. + private static SerializedProperty s_pathProperty { get; set; } + + // This property will always return the most recent serializedProperty. + public SerializedProperty pathProperty { get => s_pathProperty;} + public Action onModified { get; } private GUIContent m_PathLabel; diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPickerDropdown.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPickerDropdown.cs index 6609f622f5..f3887c7e4b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPickerDropdown.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/ControlPicker/InputControlPickerDropdown.cs @@ -58,11 +58,6 @@ public void SetExpectedControlLayout(string expectedControlLayout) Reload(); } - public void SetPickedCallback(Action action) - { - m_OnPickCallback = action; - } - protected override void OnDestroy() { #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputControlPathDrawer.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputControlPathDrawer.cs index 54e921840d..1176f527d8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputControlPathDrawer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputControlPathDrawer.cs @@ -44,7 +44,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten } EditorGUI.BeginProperty(position, label, property); - m_Editor.OnGUI(position, label, property, () => property.serializedObject.ApplyModifiedProperties()); + m_Editor.OnGUI(position, label, property: null, modifiedCallback: () => property.serializedObject.ApplyModifiedProperties()); EditorGUI.EndProperty(); } }