Skip to content

Conversation

@ekcoh
Copy link
Collaborator

@ekcoh ekcoh commented Nov 4, 2025

Description

This is a suggested fix for HUP: https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1746

Follows suggested approach in: https://discussions.unity.com/t/changes-to-assetdatabase-apis-when-called-during-import/1689358, but not exactly since that approach suggest generating a .cs file in library temp folder in that case which doesn't really solve anything for this use case.

This PR do not fix the existing problems:

  • The feature goes against recommendations for how to handle and import assets:
  • The generated code is not fully synced with the referenced asset, it gets regenerated when the asset is updated, but isn't properly moved with the asset (could be fixed), deleted with the asset (could be fixed), and doesn't get regenerated if deleted (could potentially be fixed).

Generally, IMO we should consider adding this feature to the list of potential things to remove.

Testing status & QA

Only tested manually with 6000.3 beta.

Overall Product Risks

  • Complexity: Small
  • Halo Effect: Medium

We need to ensure there is not new side-effects to projects and/or CI with the change in approach.

Comments to reviewers

Nothing special to call out apart from this being modified previously due to CI hanging in batch mode: #2091

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@ekcoh ekcoh changed the title FIX: Fix for non-deterministic behaviour in asset import stages. FIX: ISXB-1746 Fix for non-deterministic behaviour in asset import stages. Nov 4, 2025
@ekcoh ekcoh marked this pull request as ready for review November 4, 2025 10:38
@u-pr-agent
Copy link
Contributor

u-pr-agent bot commented Nov 4, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪

The PR consists of a targeted refactoring to move logic to a different Unity Editor callback, which is a standard pattern for fixing the described import issue, making the changes relatively straightforward to understand.
🏅 Score: 90

The PR effectively addresses a critical hanging issue by moving code generation to a more appropriate callback. The code is clean and the change is well-justified. The score is not higher due to a minor regression in error reporting UX and the absence of new automated tests.
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Degraded Error Reporting

The change from ctx.LogImportError to Debug.LogError means that code generation errors will no longer be directly associated with the asset in the Project view, but will appear as general console errors. Please validate if this user experience regression is acceptable.

Debug.LogError(
    $"{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;
  • Update review

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent

Comment on lines 384 to 390
var importer = GetAtPath(assetPath) as InputActionImporter;
if (importer != null)
{
var asset = InputActionAsset.FromJson(File.ReadAllText(assetPath));
if (importer.m_GenerateWrapperCode)
GenerateWrapperCode(assetPath, asset, importer.m_WrapperCodeNamespace, importer.m_WrapperClassName, importer.m_WrapperCodePath);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: The current implementation reads and parses the asset file even if code generation is disabled, which is inefficient. Additionally, it lacks error handling for file I/O and JSON parsing, which can crash the asset import process. To improve robustness and performance, first check if code generation is enabled, then wrap the file operations in a try-catch block and check for a null asset. [possible issue, importance: 8]

Suggested change
var importer = GetAtPath(assetPath) as InputActionImporter;
if (importer != null)
{
var asset = InputActionAsset.FromJson(File.ReadAllText(assetPath));
if (importer.m_GenerateWrapperCode)
GenerateWrapperCode(assetPath, asset, importer.m_WrapperCodeNamespace, importer.m_WrapperClassName, importer.m_WrapperCodePath);
}
var importer = GetAtPath(assetPath) as InputActionImporter;
if (importer != null && importer.m_GenerateWrapperCode)
{
try
{
var asset = InputActionAsset.FromJson(File.ReadAllText(assetPath));
if (asset != null)
GenerateWrapperCode(assetPath, asset, importer.m_WrapperCodeNamespace, importer.m_WrapperClassName, importer.m_WrapperCodePath);
}
catch (Exception e)
{
Debug.LogError($"Failed to generate wrapper code for '{assetPath}': {e}");
}
}

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My bad, will update to fix. Also realise we can keep error as importer error by adjusting it slightly. Will update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 87babcc

@codecov-github-com
Copy link

codecov-github-com bot commented Nov 4, 2025

Codecov Report

Attention: Patch coverage is 14.28571% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...System/Editor/AssetImporter/InputActionImporter.cs 14.28% 18 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2273      +/-   ##
===========================================
+ Coverage    76.70%   76.81%   +0.10%     
===========================================
  Files          465      476      +11     
  Lines        87919    88726     +807     
===========================================
+ Hits         67442    68155     +713     
- Misses       20477    20571      +94     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.39% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_2022.3_project 74.69% <14.28%> (+0.10%) ⬆️
inputsystem_MacOS_6000.0 5.17% <0.00%> (-0.02%) ⬇️
inputsystem_MacOS_6000.0_project 76.60% <14.28%> (+0.09%) ⬆️
inputsystem_MacOS_6000.2 5.17% <0.00%> (-0.02%) ⬇️
inputsystem_MacOS_6000.2_project 76.59% <14.28%> (+0.09%) ⬆️
inputsystem_MacOS_6000.3 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_MacOS_6000.3_project 76.60% <14.28%> (+0.10%) ⬆️
inputsystem_MacOS_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 76.61% <14.28%> (+0.10%) ⬆️
inputsystem_MacOS_6000.5 5.18% <0.00%> (?)
inputsystem_MacOS_6000.5_project 76.61% <14.28%> (?)
inputsystem_Ubuntu_2022.3 5.39% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_2022.3_project 74.49% <14.28%> (+0.09%) ⬆️
inputsystem_Ubuntu_6000.0 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.0_project 76.40% <14.28%> (+0.08%) ⬆️
inputsystem_Ubuntu_6000.2 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.2_project 76.40% <14.28%> (+0.08%) ⬆️
inputsystem_Ubuntu_6000.3 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Ubuntu_6000.3_project 76.40% <14.28%> (+0.08%) ⬆️
inputsystem_Ubuntu_6000.4 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 76.41% <14.28%> (+0.08%) ⬆️
inputsystem_Ubuntu_6000.5 5.19% <0.00%> (?)
inputsystem_Ubuntu_6000.5_project 76.41% <14.28%> (?)
inputsystem_Windows_2022.3 5.39% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_2022.3_project 74.81% <14.28%> (+0.09%) ⬆️
inputsystem_Windows_6000.0 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Windows_6000.0_project 76.72% <14.28%> (+0.07%) ⬆️
inputsystem_Windows_6000.2 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Windows_6000.2_project 76.72% <14.28%> (+0.07%) ⬆️
inputsystem_Windows_6000.3 5.18% <0.00%> (-0.02%) ⬇️
inputsystem_Windows_6000.3_project 76.72% <14.28%> (+0.08%) ⬆️
inputsystem_Windows_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 76.73% <14.28%> (+0.08%) ⬆️
inputsystem_Windows_6000.5 5.18% <0.00%> (?)
inputsystem_Windows_6000.5_project 76.73% <14.28%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...System/Editor/AssetImporter/InputActionImporter.cs 55.55% <14.28%> (+5.79%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

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

LGTM, I checked the original repro steps and did some exploratory testing such as trying to generate the script while importing something, moving/renaming the generated scripts, using symbols for action and map names, reimports, etc

Also looked for previously logged issues related to generated C# classes - ISXB-1257 (still fixed), ISXB-529 (was closed as won't fix, still happening), ISXB-1367 (unfixed and still occurring)

Copy link
Collaborator

@ritamerkl ritamerkl left a comment

Choose a reason for hiding this comment

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

Looks good, it would be great to have a test too.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Nov 5, 2025

Looks good, it would be great to have a test too.

The importer could definitely benefit from better test coverage but since it's indirectly covered by many tests, e.g. InputActionReferenceEditorTests and others for the "happy flow" and covered in most manual test cases I will not expand this as part of this PR.

@ekcoh ekcoh merged commit 4cf845c into develop Nov 5, 2025
128 checks passed
@ekcoh ekcoh deleted the isxb-1746-fix-importer-indetermetism branch November 5, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants