Skip to content

Commit 34925fc

Browse files
Merge branch 'develop' into isxb-1671-outoffocus-events-trigger-actions
2 parents 4009f9c + 4cf845c commit 34925fc

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ however, it has to be formatted properly to pass verification tests.
3838
- 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)
3939
- 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).
4040
- Fixed upgrading input actions containing multiple processors [ISXB-1674](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1674).
41+
- 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)
4142
- An issue where a UITK MouseEvent was triggered when changing from Scene View to Game View in the Editor has been fixed. [ISXB-1671](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1671)
4243

43-
4444
## [1.15.0] - 2025-10-03
4545

4646
### Changed

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ public override void OnImportAsset(AssetImportContext ctx)
124124
if (asset == null)
125125
return;
126126

127-
if (m_GenerateWrapperCode)
128-
GenerateWrapperCode(ctx, asset, m_WrapperCodeNamespace, m_WrapperClassName, m_WrapperCodePath);
127+
if (m_GenerateWrapperCode && HasMapWithSameNameAsAsset(asset, m_WrapperClassName))
128+
{
129+
ctx.LogImportError(
130+
$"{asset.name}: An action map in an .inputactions asset cannot be named the same as the asset itself if 'Generate C# Class' is used. "
131+
+ "You can rename the action map in the asset, rename the asset itself or assign a different C# class name in the import settings.");
132+
}
129133
}
130134

131135
internal static void SetupAsset(InputActionAsset asset)
@@ -201,26 +205,25 @@ private static void CreateInputActionReferences(InputActionAsset asset, AddObjec
201205
}
202206
}
203207

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

219223
var wrapperFilePath = codePath;
220224
if (string.IsNullOrEmpty(wrapperFilePath))
221225
{
222226
// Placed next to .inputactions file.
223-
var assetPath = ctx.assetPath;
224227
var directory = Path.GetDirectoryName(assetPath);
225228
var fileName = Path.GetFileNameWithoutExtension(assetPath);
226229
wrapperFilePath = Path.Combine(directory, fileName) + ".cs";
@@ -229,7 +232,6 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
229232
wrapperFilePath.StartsWith("../") || wrapperFilePath.StartsWith("..\\"))
230233
{
231234
// User-specified file relative to location of .inputactions file.
232-
var assetPath = ctx.assetPath;
233235
var directory = Path.GetDirectoryName(assetPath);
234236
wrapperFilePath = Path.Combine(directory, wrapperFilePath);
235237
}
@@ -258,11 +260,12 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
258260

259261
var options = new InputActionCodeGenerator.Options
260262
{
261-
sourceAssetPath = ctx.assetPath,
263+
sourceAssetPath = assetPath,
262264
namespaceName = codeNamespace,
263265
className = codeClassName,
264266
};
265267

268+
266269
if (InputActionCodeGenerator.GenerateWrapperCode(wrapperFilePath, asset, options))
267270
{
268271
// This isn't ideal and may have side effects, but we cannot avoid compiling again.
@@ -378,13 +381,30 @@ private static bool ContainsInputActionAssetPath(string[] assetPaths)
378381
private class InputActionJsonNameModifierAssetProcessor : AssetPostprocessor
379382
{
380383
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
381-
string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
384+
string[] movedAssets, string[] movedFromAssetPaths)
382385
{
383386
var needToInvalidate = false;
384387
foreach (var assetPath in importedAssets)
385388
{
386389
if (IsInputActionAssetPath(assetPath))
387390
{
391+
// Generate C# code from asset if configured via importer settings.
392+
// We generate from a parsed temporary asset here since loading the asset won't work here.
393+
var importer = GetAtPath(assetPath) as InputActionImporter;
394+
if (importer != null && importer.m_GenerateWrapperCode)
395+
{
396+
try
397+
{
398+
var asset = InputActionAsset.FromJson(File.ReadAllText(assetPath));
399+
GenerateWrapperCode(assetPath, asset, importer.m_WrapperCodeNamespace,
400+
importer.m_WrapperClassName, importer.m_WrapperCodePath);
401+
}
402+
catch (Exception e)
403+
{
404+
Debug.LogException(e);
405+
}
406+
}
407+
388408
needToInvalidate = true;
389409
CheckAndRenameJsonNameIfDifferent(assetPath);
390410
}

0 commit comments

Comments
 (0)