Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ however, it has to be formatted properly to pass verification tests.
- Limited the Add Control Scheme popup window max size to be its parent window, so that it won't resize beyond the visible area. [ISXB-1733](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1733)
- Fixed an issue where the action icon would shrink or disappear from UI when an action has a very long name. [ISXB-1650](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1650).
- Fixed upgrading input actions containing multiple processors [ISXB-1674](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1674).
- Fixed an issue that led to non-deterministic behaviour during `.inputaction` asset imports that could lead to corrupted assets or Unity hanging during asset import when "Generate C# Scripts" was active in importer settings. [ISXB-1746](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1746)

## [1.15.0] - 2025-10-03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@
if (asset == null)
return;

if (m_GenerateWrapperCode)
GenerateWrapperCode(ctx, asset, m_WrapperCodeNamespace, m_WrapperClassName, m_WrapperCodePath);
if (m_GenerateWrapperCode && HasMapWithSameNameAsAsset(asset, m_WrapperClassName))
{
ctx.LogImportError(

Check warning on line 129 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs#L128-L129

Added lines #L128 - L129 were not covered by tests
$"{asset.name}: An action map in an .inputactions asset cannot be named the same as the asset itself if 'Generate C# Class' is used. "
+ "You can rename the action map in the asset, rename the asset itself or assign a different C# class name in the import settings.");
}

Check warning on line 132 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L132 was not covered by tests
}

internal static void SetupAsset(InputActionAsset asset)
Expand Down Expand Up @@ -201,26 +205,25 @@
}
}

private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset asset, string codeNamespace, string codeClassName, string codePath)
private static bool HasMapWithSameNameAsAsset(InputActionAsset asset, string codeClassName)
{
var maps = asset.actionMaps;
// When using code generation, it is an error for any action map to be named the same as the asset itself.
// https://fogbugz.unity3d.com/f/cases/1212052/
var className = !string.IsNullOrEmpty(codeClassName) ? codeClassName : CSharpCodeHelpers.MakeTypeName(asset.name);
if (maps.Any(x =>
CSharpCodeHelpers.MakeTypeName(x.name) == className || CSharpCodeHelpers.MakeIdentifier(x.name) == className))
{
ctx.LogImportError(
$"{asset.name}: An action map in an .inputactions asset cannot be named the same as the asset itself if 'Generate C# Class' is used. "
+ "You can rename the action map in the asset, rename the asset itself or assign a different C# class name in the import settings.");
return (asset.actionMaps.Any(x =>
CSharpCodeHelpers.MakeTypeName(x.name) == className ||

Check warning on line 214 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs#L213-L214

Added lines #L213 - L214 were not covered by tests
CSharpCodeHelpers.MakeIdentifier(x.name) == className));
}

Check warning on line 216 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L216 was not covered by tests

private static void GenerateWrapperCode(string assetPath, InputActionAsset asset, string codeNamespace, string codeClassName, string codePath)
{
if (HasMapWithSameNameAsAsset(asset, codeClassName))

Check warning on line 220 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs#L219-L220

Added lines #L219 - L220 were not covered by tests
return;
}

var wrapperFilePath = codePath;
if (string.IsNullOrEmpty(wrapperFilePath))
{
// Placed next to .inputactions file.
var assetPath = ctx.assetPath;
var directory = Path.GetDirectoryName(assetPath);
var fileName = Path.GetFileNameWithoutExtension(assetPath);
wrapperFilePath = Path.Combine(directory, fileName) + ".cs";
Expand All @@ -229,7 +232,6 @@
wrapperFilePath.StartsWith("../") || wrapperFilePath.StartsWith("..\\"))
{
// User-specified file relative to location of .inputactions file.
var assetPath = ctx.assetPath;
var directory = Path.GetDirectoryName(assetPath);
wrapperFilePath = Path.Combine(directory, wrapperFilePath);
}
Expand Down Expand Up @@ -258,11 +260,12 @@

var options = new InputActionCodeGenerator.Options
{
sourceAssetPath = ctx.assetPath,
sourceAssetPath = assetPath,
namespaceName = codeNamespace,
className = codeClassName,
};


if (InputActionCodeGenerator.GenerateWrapperCode(wrapperFilePath, asset, options))
{
// This isn't ideal and may have side effects, but we cannot avoid compiling again.
Expand Down Expand Up @@ -378,13 +381,30 @@
private class InputActionJsonNameModifierAssetProcessor : AssetPostprocessor
{
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
string[] movedAssets, string[] movedFromAssetPaths)
{
var needToInvalidate = false;
foreach (var assetPath in importedAssets)
{
if (IsInputActionAssetPath(assetPath))
{
// Generate C# code from asset if configured via importer settings.
// We generate from a parsed temporary asset here since loading the asset won't work here.
var importer = GetAtPath(assetPath) as InputActionImporter;
if (importer != null && importer.m_GenerateWrapperCode)
{

Check warning on line 395 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L395 was not covered by tests
try
{
var asset = InputActionAsset.FromJson(File.ReadAllText(assetPath));
GenerateWrapperCode(assetPath, asset, importer.m_WrapperCodeNamespace,

Check warning on line 399 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs#L397-L399

Added lines #L397 - L399 were not covered by tests
importer.m_WrapperClassName, importer.m_WrapperCodePath);
}
catch (Exception e)
{
Debug.LogException(e);
}
}

Check warning on line 406 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs#L401-L406

Added lines #L401 - L406 were not covered by tests

needToInvalidate = true;
CheckAndRenameJsonNameIfDifferent(assetPath);
}
Expand Down