From e433739dea2823c1b7e967dd657d0c672e3c8647 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Thu, 5 Jun 2025 11:46:00 +0300 Subject: [PATCH 1/9] reset the default actions static field during scene load to fix it having junk after reloading --- .../Plugins/UI/InputSystemUIInputModule.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 756e192e88..bdac8c9a63 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1528,6 +1528,17 @@ public InputActionReference trackedDevicePosition set => SwapAction(ref m_TrackedDevicePositionAction, value, m_ActionsHooked, m_OnTrackedDevicePositionDelegate); } + // We should dispose the static default actions thing because otherwise it will survive domain reloads + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + static void ResetDefaultActions() + { + if (defaultActions != null) + { + defaultActions.Dispose(); + defaultActions = null; + } + } + /// /// Assigns default input actions asset and input actions, similar to how defaults are assigned when creating UI module in editor. /// Useful for creating at runtime. @@ -1665,7 +1676,6 @@ protected override void OnDisable() InputActionState.s_GlobalState.onActionControlsChanged.RemoveCallback(m_OnControlsChangedDelegate); DisableAllActions(); UnhookActions(); - UnassignActions(); base.OnDisable(); } From 6879065181ab68be9543ea8f9c78473b8b2b8393 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Fri, 6 Jun 2025 13:06:20 +0300 Subject: [PATCH 2/9] add a new regression test to improve coverage --- .../InputSystem/Plugins/UITests.InputModuleTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs index 7b32dd4ace..3b9df9f66c 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs @@ -157,6 +157,17 @@ public IEnumerator PointerExitChildShouldFullyExit() Assert.IsTrue(callbackCheck.pointerData.fullyExited == true); } + [UnityTest] + [Description("Regression test for https://jira.unity3d.com/browse/ISXB-1493")] + public IEnumerator DisablingDoesNotResetActions() + { + m_InputModule.enabled = false; + + yield return null; + + Assert.IsNotNull(m_InputModule.cancel, "Disabling component shouldn't lose its data."); + } + public class PointerExitCallbackCheck : MonoBehaviour, IPointerExitHandler { public PointerEventData pointerData { get; private set; } From f08c6fdd5bac4ee05ad20b17ff7fe0b65072765d Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Fri, 6 Jun 2025 13:10:15 +0300 Subject: [PATCH 3/9] fix up typo --- .../InputSystem.Editor/ProjectWideInputActionsEditorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs b/Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs index 9b1e31dd75..30690878b2 100644 --- a/Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs +++ b/Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs @@ -236,7 +236,7 @@ public void Report(string message) } } - [Test(Description = "Verifies that the default asset do not generate any verification errors (Regardless of existing requirements)")] + [Test(Description = "Verifies that the default asset does not generate any verification errors (Regardless of existing requirements)")] [Category(kTestCategory)] public void ProjectWideActions_ShouldSupportAssetVerification_AndHaveNoVerificationErrorsForDefaultAsset() { From d94b0e61e94503c337c48dcb5523a994070447b1 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Fri, 6 Jun 2025 13:15:33 +0300 Subject: [PATCH 4/9] update changelog --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 9915671160..1a96bc67f1 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -28,6 +28,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090) - Fixed reenabling the VirtualMouseInput component may sometimes lead to NullReferenceException. [ISXB-1096](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1096) - 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) +- Fixed actions being reset when disabling the InputSystemUIInputModule component [ISXB-1493](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1493) - Fixed PlayerInput component automatically switching away from the default ActionMap set to 'None'. - Fixed a console error being shown when targeting visionOS builds in 2022.3. - 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) From 6aa15c7fbee572fd7f5a5fdb92043c8f1dff67fa Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Wed, 25 Jun 2025 11:11:42 +0300 Subject: [PATCH 5/9] yet another attempt at addressing the ui input issues --- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index bdac8c9a63..d133fa80c0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1677,6 +1677,12 @@ protected override void OnDisable() DisableAllActions(); UnhookActions(); + // In the case we've been initialialised with default actions, we want to unalloc them + if (defaultActions != null && defaultActions.asset == actionsAsset) + { + UnassignActions(); + } + base.OnDisable(); } From f4bed15e875b0c47f67dac96b9ea2cc43c835a69 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Wed, 25 Jun 2025 11:50:20 +0300 Subject: [PATCH 6/9] use non-default asset for testing --- .../Tests/InputSystem/Plugins/UITests.InputModuleTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs index 3b9df9f66c..d56dcf458c 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs @@ -159,13 +159,19 @@ public IEnumerator PointerExitChildShouldFullyExit() [UnityTest] [Description("Regression test for https://jira.unity3d.com/browse/ISXB-1493")] - public IEnumerator DisablingDoesNotResetActions() + public IEnumerator DisablingDoesNotResetUserActions() { + var actions = new DefaultInputActions(); + m_InputModule.actionsAsset = actions.asset; + m_InputModule.cancel = InputActionReference.Create(actions.UI.Cancel); + m_InputModule.enabled = false; yield return null; Assert.IsNotNull(m_InputModule.cancel, "Disabling component shouldn't lose its data."); + + actions.Dispose(); } public class PointerExitCallbackCheck : MonoBehaviour, IPointerExitHandler From 5c996c0e28943333951c744e79ae8bce85683cbe Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Wed, 25 Jun 2025 18:42:10 +0300 Subject: [PATCH 7/9] Update Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index d133fa80c0..d5e415bb07 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1677,7 +1677,7 @@ protected override void OnDisable() DisableAllActions(); UnhookActions(); - // In the case we've been initialialised with default actions, we want to unalloc them + // In the case we've been initialized with default actions, we want to release them if (defaultActions != null && defaultActions.asset == actionsAsset) { UnassignActions(); From 29fcc49ca619f5b4905dbbb75497f107dffc7046 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Thu, 26 Jun 2025 13:40:21 +0300 Subject: [PATCH 8/9] update formatting --- .../InputSystem/Plugins/UI/InputSystemUIInputModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index d5e415bb07..2ce58a635a 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1537,7 +1537,7 @@ static void ResetDefaultActions() defaultActions.Dispose(); defaultActions = null; } - } + } /// /// Assigns default input actions asset and input actions, similar to how defaults are assigned when creating UI module in editor. From 44831d5bc33ae64b5d9da3a4c3aba402ca5adfc8 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Thu, 26 Jun 2025 13:43:28 +0300 Subject: [PATCH 9/9] update changelog with a linked case --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 1a96bc67f1..2216313079 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -29,6 +29,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed reenabling the VirtualMouseInput component may sometimes lead to NullReferenceException. [ISXB-1096](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1096) - 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) - Fixed actions being reset when disabling the InputSystemUIInputModule component [ISXB-1493](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1493) +- 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) - Fixed PlayerInput component automatically switching away from the default ActionMap set to 'None'. - Fixed a console error being shown when targeting visionOS builds in 2022.3. - 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)