Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: ISXB-1221 input action binding discarded #2119

Merged
merged 22 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ 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());
}

public void Dispose()
{
s_pathProperty = null;
m_PickerDropdown?.Dispose();
}

Expand Down Expand Up @@ -89,10 +91,10 @@ public void OnGUI()
EditorGUILayout.EndHorizontal();
}

//TODO: on next major version remove property argument.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend filing a JIRA ticket on this if/when this lands, otherwise it would be forgotten.

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;
Expand All @@ -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
{
Expand All @@ -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();
}
}
Expand All @@ -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);
}
}

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static SerializedProperty, wouldn't it leak memory? Its referencing a SerializedObject that was dynamically allocated and may/would be disposed from outside this editor?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally this assumes there can only exist one InputControlPathEditor instance right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there will be a dangling reference tht may hang around. I'll add some code to clean it up when the editor is closed.

Yes, only one instance of the InputControlPathEditor will work at a time. I think this is ok, as it is a popup window, and disappears when it loses focus.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// This property will always return the most recent serializedProperty.
public SerializedProperty pathProperty { get => s_pathProperty;}

public Action onModified { get; }

private GUIContent m_PathLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ public void SetExpectedControlLayout(string expectedControlLayout)
Reload();
}

public void SetPickedCallback(Action<string> action)
{
m_OnPickCallback = action;
}

protected override void OnDestroy()
{
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down