Skip to content
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed the compilation warnings when used with Unity 6.4 (ISX-2349).
- Fixed an issue where `InputSystemUIInputModule.localMultiPlayerRoot` could not be set to `null` when using `MultiplayerEventSystem`. [ISXB-1610](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1610)
- Fixed an issue in `Keyboard` where the sub-script operator would return a `null` key control for the deprecated key `Key.IMESelected`. Now, an aliased `KeyControl`mapping to the IMESelected bit is returned for compability reasons. It is still strongly advised to not rely on this key since `IMESelected` bit isn't strictly a key and will be removed from the `Key` enumeration type in a future major revision. [ISXB-1541](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1541).
- Fixed an ArgumentOutOfRangeException that was thrown when pressing the undo shortcut while changing a control scheme name. [ISXB-1607](https://issuetracker.unity3d.com/issues/argumentoutofrangeexception-error-is-thrown-when-pressing-the-undo-shortcut-while-changing-the-control-scheme-name)

## [1.14.2] - 2025-08-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@
{
return (in InputActionsEditorState state) =>
{
var controlSchemeSerializedProperty = state.selectedControlSchemeIndex == -1 ? null :
state.serializedObject
.FindProperty(nameof(InputActionAsset.m_ControlSchemes))
.GetArrayElementAtIndex(state.selectedControlSchemeIndex);
SerializedProperty controlSchemeSerializedProperty = null;
var serializedProperty = state.serializedObject

Check warning on line 149 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L148-L149

Added lines #L148 - L149 were not covered by tests
.FindProperty(nameof(InputActionAsset.m_ControlSchemes));

if (state.selectedControlSchemeIndex < serializedProperty.arraySize)
{
controlSchemeSerializedProperty = state.selectedControlSchemeIndex == -1 ? null :

Check warning on line 154 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L152-L154

Added lines #L152 - L154 were not covered by tests
serializedProperty
.GetArrayElementAtIndex(state.selectedControlSchemeIndex);
}

Check warning on line 157 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/ControlSchemeCommands.cs#L157

Added line #L157 was not covered by tests

if (controlSchemeSerializedProperty == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ private void RemoveDeviceRequirement()
public override void RedrawUI(InputControlScheme viewState)
{
rootElement.Q<TextField>(kControlSchemeNameTextField).value = string.IsNullOrEmpty(m_NewName) ? viewState.name : m_NewName;

m_ListView.itemsSource?.Clear();
m_ListView.itemsSource = viewState.deviceRequirements.Count > 0 ?
viewState.deviceRequirements.Select(r => (r.controlPath, r.isOptional)).ToList() :
Expand All @@ -128,7 +127,7 @@ private void SaveAndClose()
CloseView();
}

private void Cancel()
internal void Cancel()
{
// Reload the selected ControlScheme values from the SerilaizedProperty and throw away any changes
Dispatch(ControlSchemeCommands.ResetSelectedControlScheme());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
Expand All @@ -24,6 +25,8 @@

private readonly Action m_SaveAction;

private ControlSchemesView m_ControlSchemesView;

public InputActionsEditorView(VisualElement root, StateContainer stateContainer, bool isProjectSettings,
Action saveAction)
: base(root, stateContainer)
Expand Down Expand Up @@ -104,6 +107,27 @@
});

s_OnPasteCutElements.Add(this);

Undo.undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I am misunderstanding this PR/issue so I want to check whether this problem is if you undo text editing while in text editing mode? Such editing should not have been applied yet to any serializedProperty right or am I misunderstanding this issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a bit different than that, basically the last undo when opening a control scheme to edit is the creation of the asset.

Therefore undoing while editing the name actually deletes the asset.
This of course causes exceptions when inside the edit window if you try to alter the asset or even try to close it.

My solution I have landed on for now is to close the control scheme view when this happens and revert to selecting the all controls control scheme now instead.

}

private async void CheckForInvalidControlSchemeInOneFrame()
{

Check warning on line 115 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L115

Added line #L115 was not covered by tests
try
{
await Task.Delay(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This await Task.Delay(1) raises warning flags to me. What guarantees this is valid to execute 1 second from now?

  • Why does it have to be delayed?
  • It looks like this runs async but code being accessed do not seem to be thread safe?
  • Is there a logical condition not based on time when this is valid to execute?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, it was something I added at the end to solve an exception but it's not the correct way to do this.

I have now resorted to just closing the window when an undo is triggered if it's open.

This has one side effect though that it will trigger the view to close in a case where it might not need to, definitely less bad than all the exceptions it could cause previously.

The best solution that I could not figure out a way to do would be to add the opening of the control scheme editor popup to the undo stack so that pressing undo would close it, I did find a way to possibly do this but it would add a good amount of complexity and would be quite hacky.

I chose not to go this route in the end as the undo api is not really designed to be used with things that are not Objects/GameObjects.

var state = stateContainer.GetState();
var viewState = ViewStateSelector.GetViewState(state);
var elementAtOrDefault = viewState.controlSchemes?.ElementAtOrDefault(viewState.selectedControlSchemeIndex);
if (viewState.selectedControlSchemeIndex != -1 && elementAtOrDefault == default(InputControlScheme))
{
m_ControlSchemesView?.Cancel();
}
}
catch (Exception e)
{
Debug.LogException(e);
}

Check warning on line 130 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L117-L130

Added lines #L117 - L130 were not covered by tests
}

private void OnReset()
Expand Down Expand Up @@ -156,9 +180,8 @@

if (viewState.controlSchemes.Any())
{
m_ControlSchemesToolbar.text = viewState.selectedControlSchemeIndex == -1
? "All Control Schemes"
: viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex).name;
var elementAtOrDefault = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex);
m_ControlSchemesToolbar.text = elementAtOrDefault == default ? "All Control Schemes" : elementAtOrDefault.name;

Check warning on line 184 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L183-L184

Added lines #L183 - L184 were not covered by tests

m_ControlSchemesToolbar.menu.AppendAction("All Control Schemes", _ => SelectControlScheme(-1),
viewState.selectedControlSchemeIndex == -1 ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);
Expand Down Expand Up @@ -186,7 +209,7 @@
return;
}
m_DevicesToolbar.SetEnabled(true);
var currentControlScheme = viewState.controlSchemes.ElementAt(viewState.selectedControlSchemeIndex);
var currentControlScheme = viewState.controlSchemes.ElementAtOrDefault(viewState.selectedControlSchemeIndex);

Check warning on line 212 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L212

Added line #L212 was not covered by tests
if (viewState.selectedDeviceIndex == -1)
m_DevicesToolbar.text = "All Devices";

Expand Down Expand Up @@ -228,10 +251,13 @@

private void ShowControlSchemeEditor(VisualElement parent, bool updateExisting = false)
{
var controlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting));
controlSchemesView.UpdateView(stateContainer.GetState());

controlSchemesView.OnClosing += _ => DestroyChildView(controlSchemesView);
m_ControlSchemesView = CreateChildView(new ControlSchemesView(parent, stateContainer, updateExisting));
m_ControlSchemesView.UpdateView(stateContainer.GetState());
m_ControlSchemesView.OnClosing += _ =>
{
DestroyChildView(m_ControlSchemesView);
m_ControlSchemesView = null;
};

Check warning on line 260 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/InputActionsEditorView.cs#L254-L260

Added lines #L254 - L260 were not covered by tests
}

private void SelectControlScheme(int controlSchemeIndex)
Expand All @@ -258,6 +284,7 @@
{
base.DestroyView();
s_OnPasteCutElements.Remove(this);
Undo.undoRedoPerformed -= CheckForInvalidControlSchemeInOneFrame;
}

public void OnPaste(InputActionsEditorState state)
Expand Down