Skip to content

Commit a89c735

Browse files
authored
FIX: Fixed InputManager.asset file growing in size on each Reset call (#1821)
* Reset now clears out old Input Action Assets and Input Action References first with a DeleteActionAsset call in CreateNewActionAsset to make sure we never create duplicates
1 parent 4a77265 commit a89c735

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ however, it has to be formatted properly to pass verification tests.
3636
- Fixed missing name in window title for Input Action assets.
3737
- Fixed showing action properties view when there were no actions.
3838
- Fixed "Listen" functionality for selecting an input sometimes expecting the wrong input type.
39+
- Fixed InputManager.asset file growing in size on each Reset call.
3940

4041
## [1.8.0-pre.2] - 2023-11-09
4142

Packages/com.unity.inputsystem/InputSystem/Editor/ProjectWideActions/ProjectWideActionsAsset.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ internal static InputActionAsset GetOrCreate()
5353

5454
internal static InputActionAsset CreateNewActionAsset()
5555
{
56+
// Always clean out old actions asset and action references first before we add new
57+
DeleteActionAssetAndActionReferences();
58+
59+
// Create new asset data
5660
var json = File.ReadAllText(FileUtil.GetPhysicalPath(s_DefaultAssetPath));
5761

5862
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
@@ -87,7 +91,6 @@ internal static InputActionAsset CreateNewActionAsset()
8791
}
8892

8993
CreateInputActionReferences(asset);
90-
9194
AssetDatabase.SaveAssets();
9295

9396
return asset;
@@ -114,7 +117,7 @@ private static void CreateInputActionReferences(InputActionAsset asset)
114117
}
115118
}
116119

117-
#if UNITY_2023_2_OR_NEWER
120+
#if UNITY_2023_2_OR_NEWER
118121
/// <summary>
119122
/// Checks if the default UI action map has been modified or removed, to let the user know if their changes will
120123
/// break the UI input at runtime, when using the UI Toolkit.
@@ -147,13 +150,44 @@ internal static void CheckForDefaultUIActionMapChanges()
147150
}
148151
}
149152

150-
#endif
153+
#endif
154+
/// <summary>
155+
/// Reset project wide input actions asset
156+
/// </summary>
157+
internal static void ResetActionAsset()
158+
{
159+
CreateNewActionAsset();
160+
}
161+
162+
/// <summary>
163+
/// Delete project wide input actions
164+
/// </summary>
165+
internal static void DeleteActionAssetAndActionReferences()
166+
{
167+
var objects = AssetDatabase.LoadAllAssetsAtPath(s_AssetPath);
168+
if (objects != null)
169+
{
170+
// Handle deleting all InputActionAssets as older 1.8.0 pre release could create more than one project wide input asset in the file
171+
foreach (var obj in objects)
172+
{
173+
if (obj is InputActionReference)
174+
{
175+
var actionReference = obj as InputActionReference;
176+
actionReference.Set(null);
177+
AssetDatabase.RemoveObjectFromAsset(obj);
178+
}
179+
else if (obj is InputActionAsset)
180+
{
181+
AssetDatabase.RemoveObjectFromAsset(obj);
182+
}
183+
}
184+
}
185+
}
151186

152187
/// <summary>
153188
/// Updates the input action references in the asset by updating names, removing dangling references
154189
/// and adding new ones.
155190
/// </summary>
156-
/// <param name="asset"></param>
157191
internal static void UpdateInputActionReferences()
158192
{
159193
var asset = GetOrCreate();
@@ -195,6 +229,8 @@ internal static void UpdateInputActionReferences()
195229
}
196230
}
197231
}
232+
233+
AssetDatabase.SaveAssets();
198234
}
199235
}
200236
}

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ public static Command ResetGlobalInputAsset(Action<InputActionAsset> postResetAc
425425
{
426426
return (in InputActionsEditorState state) =>
427427
{
428-
var asset = ProjectWideActionsAsset.CreateNewActionAsset();
428+
ProjectWideActionsAsset.ResetActionAsset();
429+
var asset = ProjectWideActionsAsset.GetOrCreate();
429430
postResetAction?.Invoke(asset);
430431
return state;
431432
};

0 commit comments

Comments
 (0)