From 31d97ade55d8a4fcaf4ebbe82d7eb7d9f7981638 Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Tue, 1 Apr 2025 13:21:53 +0300 Subject: [PATCH 1/2] don't overwrite user files that happened to be called the same as the input actions target --- .../Editor/AssetImporter/InputActionImporter.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs index d1d9db335f..4eb0826fc0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs @@ -247,6 +247,18 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); + // Check for the case where the target file already exists. + // If it does, we don't want to overwrite it unless it's been generated by us before. + if (File.Exists(wrapperFilePath)) + { + var text = File.ReadAllText(wrapperFilePath); + var autoGeneratedMarker = "This code was auto-generated by com.unity.inputsystem"; + if (!text.Contains(autoGeneratedMarker)) + { + 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. "); + } + } + var options = new InputActionCodeGenerator.Options { sourceAssetPath = ctx.assetPath, From 33d35fd32ac1e83508a0819a3497d9aa7f36017f Mon Sep 17 00:00:00 2001 From: Anthony Yakovlev Date: Tue, 1 Apr 2025 13:24:24 +0300 Subject: [PATCH 2/2] update changelog --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 0a7ecaf744..56e23376c0 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed an issue causing a number of errors to be displayed when using `InputTestFixture` in playmode tests with domain reloading disabled on playmode entry. [ISXB-1446](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1446) - 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) - 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) +- 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) ## [1.14.0] - 2025-03-20