Skip to content

Commit ce32d45

Browse files
Add better fix for undo bug in control scheme editor.
1 parent e972f16 commit ce32d45

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Threading.Tasks;
56
using UnityEditor;
67
using UnityEditor.UIElements;
78
using UnityEngine.UIElements;
@@ -93,7 +94,7 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer,
9394

9495
// only register the state changed event here in the parent. Changes will be cascaded
9596
// into child views.
96-
stateContainer.StateChanged += StateChanged(stateContainer);
97+
stateContainer.StateChanged += OnStateChanged;
9798

9899
CreateSelector(
99100
s => s.selectedControlSchemeIndex,
@@ -106,22 +107,27 @@ public InputActionsEditorView(VisualElement root, StateContainer stateContainer,
106107
});
107108

108109
s_OnPasteCutElements.Add(this);
110+
111+
Undo.undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame;
109112
}
110113

111-
private Action<InputActionsEditorState, UIRebuildMode> StateChanged(StateContainer stateContainer)
114+
private async void CheckForInvalidControlSchemeInOneFrame()
112115
{
113-
return (inputActionsEditorState, uiRebuildMode) =>
116+
try
114117
{
118+
await Task.Delay(1);
115119
var state = stateContainer.GetState();
116120
var viewState = ViewStateSelector.GetViewState(state);
117121
var elementAtOrDefault = viewState.controlSchemes?.ElementAtOrDefault(viewState.selectedControlSchemeIndex);
118122
if (viewState.selectedControlSchemeIndex != -1 && elementAtOrDefault == default(InputControlScheme))
119123
{
120124
m_ControlSchemesView?.Cancel();
121125
}
122-
123-
OnStateChanged(inputActionsEditorState, uiRebuildMode);
124-
};
126+
}
127+
catch (Exception e)
128+
{
129+
Debug.LogException(e);
130+
}
125131
}
126132

127133
private void OnReset()
@@ -278,6 +284,7 @@ public override void DestroyView()
278284
{
279285
base.DestroyView();
280286
s_OnPasteCutElements.Remove(this);
287+
Undo.undoRedoPerformed -= CheckForInvalidControlSchemeInOneFrame;
281288
}
282289

283290
public void OnPaste(InputActionsEditorState state)

0 commit comments

Comments
 (0)