Skip to content
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputActionAsset>();
Expand Down Expand Up @@ -87,7 +91,6 @@ internal static InputActionAsset CreateNewActionAsset()
}

CreateInputActionReferences(asset);

AssetDatabase.SaveAssets();

return asset;
Expand All @@ -114,7 +117,7 @@ private static void CreateInputActionReferences(InputActionAsset asset)
}
}

#if UNITY_2023_2_OR_NEWER
#if UNITY_2023_2_OR_NEWER
/// <summary>
/// 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.
Expand Down Expand Up @@ -147,13 +150,44 @@ internal static void CheckForDefaultUIActionMapChanges()
}
}

#endif
#endif
/// <summary>
/// Reset project wide input actions asset
/// </summary>
internal static void ResetActionAsset()
{
CreateNewActionAsset();
}

/// <summary>
/// Delete project wide input actions
/// </summary>
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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is something here that isn't an InputActionReference or an InpuitAction asset?
I recommend we either throw or log an error or alternatively change the last else if into an unconditional else which would remove anything? Or is this designed to leave e.g. InputManager or any other root objects untouched?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its designed to leave InputManager and others untouched

}
}
}

/// <summary>
/// Updates the input action references in the asset by updating names, removing dangling references
/// and adding new ones.
/// </summary>
/// <param name="asset"></param>
internal static void UpdateInputActionReferences()
{
var asset = GetOrCreate();
Expand Down Expand Up @@ -195,6 +229,8 @@ internal static void UpdateInputActionReferences()
}
}
}

AssetDatabase.SaveAssets();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ public static Command ResetGlobalInputAsset(Action<InputActionAsset> postResetAc
{
return (in InputActionsEditorState state) =>
{
var asset = ProjectWideActionsAsset.CreateNewActionAsset();
ProjectWideActionsAsset.ResetActionAsset();
var asset = ProjectWideActionsAsset.GetOrCreate();
postResetAction?.Invoke(asset);
return state;
};
Expand Down