Skip to content

Commit 3f65a3c

Browse files
authored
FIX: Fixed Input Actions code generation overwriting user files when the names happened to match. (#2159)
1 parent 70b54a3 commit 3f65a3c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ however, it has to be formatted properly to pass verification tests.
1616
- Fixed issue where user was not prompted to save changes when loading a second input actions asset into an already opened editor. [ISXB-1343](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1343)
1717
- Fixed the on hover behaviour of the two plus buttons in the Input Actions Editor window [ISXB-1327](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1327)
1818
- Fixed an issue on macOS which didn't detect up-left DPAD presses for Xbox controllers. [ISXB-810](https://issuetracker.unity3d.com/issues/macos-d-pad-upper-left-corner-is-not-logged-with-the-xbox-controller)
19+
- Fixed Input Actions code generation overwriting user files when the names happened to match. [ISXB-1257](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1257)
1920
- Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897)
2021

2122
## [1.14.0] - 2025-03-20

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
247247
if (!Directory.Exists(dir))
248248
Directory.CreateDirectory(dir);
249249

250+
// Check for the case where the target file already exists.
251+
// If it does, we don't want to overwrite it unless it's been generated by us before.
252+
if (File.Exists(wrapperFilePath))
253+
{
254+
var text = File.ReadAllText(wrapperFilePath);
255+
var autoGeneratedMarker = "This code was auto-generated by com.unity.inputsystem";
256+
if (!text.Contains(autoGeneratedMarker))
257+
{
258+
throw new Exception($"The target file for Input Actions code generation already exists: {wrapperFilePath}. Since it doesn't look to contain Input generated code that we can safely overwrite, we stopped to prevent any data loss. Consider renaming. ");
259+
}
260+
}
261+
250262
var options = new InputActionCodeGenerator.Options
251263
{
252264
sourceAssetPath = ctx.assetPath,

0 commit comments

Comments
 (0)