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() { diff --git a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs index 7b32dd4ace..d56dcf458c 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs @@ -157,6 +157,23 @@ public IEnumerator PointerExitChildShouldFullyExit() Assert.IsTrue(callbackCheck.pointerData.fullyExited == true); } + [UnityTest] + [Description("Regression test for https://jira.unity3d.com/browse/ISXB-1493")] + 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 { public PointerEventData pointerData { get; private set; } diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 9915671160..2216313079 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -28,6 +28,8 @@ 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 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) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 756e192e88..2ce58a635a 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,12 @@ protected override void OnDisable() InputActionState.s_GlobalState.onActionControlsChanged.RemoveCallback(m_OnControlsChangedDelegate); DisableAllActions(); UnhookActions(); - UnassignActions(); + + // In the case we've been initialized with default actions, we want to release them + if (defaultActions != null && defaultActions.asset == actionsAsset) + { + UnassignActions(); + } base.OnDisable(); }