Skip to content

Commit 4f6aca6

Browse files
K-ToneCopilot
andauthored
FIX: disabling the InputSystemUIInputModule component resets all actions to None (#2192)
Co-authored-by: Copilot <[email protected]>
1 parent 2315a74 commit 4f6aca6

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void Report(string message)
236236
}
237237
}
238238

239-
[Test(Description = "Verifies that the default asset do not generate any verification errors (Regardless of existing requirements)")]
239+
[Test(Description = "Verifies that the default asset does not generate any verification errors (Regardless of existing requirements)")]
240240
[Category(kTestCategory)]
241241
public void ProjectWideActions_ShouldSupportAssetVerification_AndHaveNoVerificationErrorsForDefaultAsset()
242242
{

Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ public IEnumerator PointerExitChildShouldFullyExit()
157157
Assert.IsTrue(callbackCheck.pointerData.fullyExited == true);
158158
}
159159

160+
[UnityTest]
161+
[Description("Regression test for https://jira.unity3d.com/browse/ISXB-1493")]
162+
public IEnumerator DisablingDoesNotResetUserActions()
163+
{
164+
var actions = new DefaultInputActions();
165+
m_InputModule.actionsAsset = actions.asset;
166+
m_InputModule.cancel = InputActionReference.Create(actions.UI.Cancel);
167+
168+
m_InputModule.enabled = false;
169+
170+
yield return null;
171+
172+
Assert.IsNotNull(m_InputModule.cancel, "Disabling component shouldn't lose its data.");
173+
174+
actions.Dispose();
175+
}
176+
160177
public class PointerExitCallbackCheck : MonoBehaviour, IPointerExitHandler
161178
{
162179
public PointerEventData pointerData { get; private set; }

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ however, it has to be formatted properly to pass verification tests.
2828
- Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090)
2929
- Fixed reenabling the VirtualMouseInput component may sometimes lead to NullReferenceException. [ISXB-1096](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1096)
3030
- Fixed the default button press point not being respected in Editor (as well as some other Touchscreen properties). [ISXB-1152](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1152)
31+
- Fixed actions being reset when disabling the InputSystemUIInputModule component [ISXB-1493](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1493)
32+
- Fixed a memory leak when disabling and enabling the InputSystemUIInputModule component at runtime [ISXB-1573](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1573)
3133
- Fixed PlayerInput component automatically switching away from the default ActionMap set to 'None'.
3234
- Fixed a console error being shown when targeting visionOS builds in 2022.3.
3335
- Fixed a Tap Interaction issue with analog controls. The Tap interaction would keep re-starting after timeout. [ISXB-627](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-627)

Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,17 @@ public InputActionReference trackedDevicePosition
15281528
set => SwapAction(ref m_TrackedDevicePositionAction, value, m_ActionsHooked, m_OnTrackedDevicePositionDelegate);
15291529
}
15301530

1531+
// We should dispose the static default actions thing because otherwise it will survive domain reloads
1532+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
1533+
static void ResetDefaultActions()
1534+
{
1535+
if (defaultActions != null)
1536+
{
1537+
defaultActions.Dispose();
1538+
defaultActions = null;
1539+
}
1540+
}
1541+
15311542
/// <summary>
15321543
/// Assigns default input actions asset and input actions, similar to how defaults are assigned when creating UI module in editor.
15331544
/// Useful for creating <see cref="InputSystemUIInputModule"/> at runtime.
@@ -1665,7 +1676,12 @@ protected override void OnDisable()
16651676
InputActionState.s_GlobalState.onActionControlsChanged.RemoveCallback(m_OnControlsChangedDelegate);
16661677
DisableAllActions();
16671678
UnhookActions();
1668-
UnassignActions();
1679+
1680+
// In the case we've been initialized with default actions, we want to release them
1681+
if (defaultActions != null && defaultActions.asset == actionsAsset)
1682+
{
1683+
UnassignActions();
1684+
}
16691685

16701686
base.OnDisable();
16711687
}

0 commit comments

Comments
 (0)