diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 47c687d06d..a86d56b371 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -36,6 +36,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed missing name in window title for Input Action assets. - Fixed showing action properties view when there were no actions. - Fixed "Listen" functionality for selecting an input sometimes expecting the wrong input type. +- Fixed InputManager.asset file growing in size on each Reset call. ## [1.8.0-pre.2] - 2023-11-09 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs index e20bedefd4..f56024fa49 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs @@ -53,6 +53,10 @@ internal static InputActionAsset GetOrCreate() internal static InputActionAsset CreateNewActionAsset() { + // Always clean out old actions asset and action references first before we add new + DeleteActionAssetAndActionReferences(); + + // Create new asset data var json = File.ReadAllText(FileUtil.GetPhysicalPath(s_DefaultAssetPath)); var asset = ScriptableObject.CreateInstance(); @@ -87,7 +91,6 @@ internal static InputActionAsset CreateNewActionAsset() } CreateInputActionReferences(asset); - AssetDatabase.SaveAssets(); return asset; @@ -114,7 +117,7 @@ private static void CreateInputActionReferences(InputActionAsset asset) } } - #if UNITY_2023_2_OR_NEWER +#if UNITY_2023_2_OR_NEWER /// /// Checks if the default UI action map has been modified or removed, to let the user know if their changes will /// break the UI input at runtime, when using the UI Toolkit. @@ -147,13 +150,44 @@ internal static void CheckForDefaultUIActionMapChanges() } } - #endif +#endif + /// + /// Reset project wide input actions asset + /// + internal static void ResetActionAsset() + { + CreateNewActionAsset(); + } + + /// + /// Delete project wide input actions + /// + internal static void DeleteActionAssetAndActionReferences() + { + var objects = AssetDatabase.LoadAllAssetsAtPath(s_AssetPath); + if (objects != null) + { + // Handle deleting all InputActionAssets as older 1.8.0 pre release could create more than one project wide input asset in the file + foreach (var obj in objects) + { + if (obj is InputActionReference) + { + var actionReference = obj as InputActionReference; + actionReference.Set(null); + AssetDatabase.RemoveObjectFromAsset(obj); + } + else if (obj is InputActionAsset) + { + AssetDatabase.RemoveObjectFromAsset(obj); + } + } + } + } /// /// Updates the input action references in the asset by updating names, removing dangling references /// and adding new ones. /// - /// internal static void UpdateInputActionReferences() { var asset = GetOrCreate(); @@ -195,6 +229,8 @@ internal static void UpdateInputActionReferences() } } } + + AssetDatabase.SaveAssets(); } } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs index fe0f9763a4..d0eed0dce2 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs @@ -425,7 +425,8 @@ public static Command ResetGlobalInputAsset(Action postResetAc { return (in InputActionsEditorState state) => { - var asset = ProjectWideActionsAsset.CreateNewActionAsset(); + ProjectWideActionsAsset.ResetActionAsset(); + var asset = ProjectWideActionsAsset.GetOrCreate(); postResetAction?.Invoke(asset); return state; };