Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Delayed input backend prompt to make sure asset import is not interrupted (ISXB-608) #2107

Merged
merged 5 commits into from
Jan 17, 2025

Conversation

ritamerkl
Copy link
Collaborator

@ritamerkl ritamerkl commented Jan 15, 2025

Description

Like described in this ticket ISXB-608 the prompt to activate the InputSystem backend is delayed to after assets are imported. This means the prompt will appear once the editor launched, and in case of the package being imported after all assets loaded in the current domain reload.

FYI: The delayCall is called AFTER domain reloads when the UI inspectors update.

The dependency to the InputSystem (for affected assets eg Enemies) should be updated to the latest version after this change.

Testing status & QA

I tested this for editor launches and importing the package in newly created projects. Testing this in combination with importing assets is cumbersome, since the import happens based on the version define of the asset dependency.

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity: Low
  • Halo Effect: Low

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

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.

@ritamerkl ritamerkl requested review from Pauliusd01, jfreire-unity and unity-cliff and removed request for jfreire-unity January 15, 2025 16:05
@Pauliusd01

This comment was marked as resolved.

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, here's what I've checked:

  • Adding just the Input System package while the Editor is open/closed
  • Bundling the Input System package with some large, valid assets to import (Editor open) - Pass - packages/assets were imported first -> only then I got the dialog
  • Bundling the Input System package with some large, valid assets to import (Editor closed) - Pass - packages/assets were imported first -> Editor opened and I got the dialog
  • Bundling the Input System package with some erroring out assets (Editor open) - Pass
  • Bundling the Input System package with some erroring out assets (Editor closed) - Pass - safe mode did not interfere with the dialog order
  • Reimport All option (Input Manager backend) - Pass - got the prompt on reimport
  • Reimport All option (Input System backend) - Pass - no unnecessary prompt or backend resets


// If native backends for new input system aren't enabled, ask user whether we should
// enable them (requires restart). We only ask once per session and don't ask when
// running in batch mode.
// The warning is delayed to delay call (called a short while after the Asset are loaded, on Inspector update) to make sure it doesn't pop up while the editor is still loading or assets are not fully loaded -
// this would cancel the import of large assets that are dependent on the InputSystem package and import it as a dependency.
EditorApplication.delayCall += ShowRestartWarning;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this guarantee that it will execute after asset import? I would have expected this to be triggered by an AssetP since this one will simply but the callback on the editor event queue?
If it works its great, but felt I was not seeing how this is robust.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The AssetPostProcessor was an other option I considered, but it requires another class to inherit from AssetPostprocessor, so I decided for delayedCall instead. delayCall is called after domain reloads (which include importing of assets at the end) when the inspector windows refresh, which I think is suitable for a prompt. I don't see why it's not robust, in which way do you think it couldn't be?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, yeah we have some classes doing that as part of InputActionImporter. If delayCall runs after domain reloads it's good, but to me it wasn't clear it runs after asset import (which might not trigger a domain reload if no code changed?). At least it's not explicit from https://docs.unity3d.com/6000.0/Documentation/ScriptReference/EditorApplication-delayCall.html, so it seems to relate to inspectors but not necessarily asset imports? Maybe you know something I do not in this area, but to me it wasn't clear that e.g. delayCall could be executed between two imports.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since InitializeInEditor is called from the static constructor it's only executed when the editor launches or the package gets added into the project (afaik - correct me if I forgot a case), in both cases there is a domain reload happening.
Here a short explanation why I think the call is reliable:
The callbacks in delayCall are invoked in the subsequent editor update.
Editor updates do not happen during a domain reload (which includes import of assets - no matter how many), Editor updates resume only after the domain reload is complete.
One reason for this is that Editor updates depend on stable managed objects and assemblies. Since these objects are being reloaded, updates during this period could result in crashes or undefined behavior.

// this would cancel the import of large assets that are dependent on the InputSystem package and import it as a dependency.
EditorApplication.delayCall += ShowRestartWarning;

#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would also be great to understand why this was moved out of its previous place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put it into a private function of the same class to make it more readable, I think having big chunks of code in single functions do no good for the readability some times. (technically still in the same place though)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure I see the function you are referring to? What I meant was basically that previously EnableActions(), RunInitialUpdate(), was executed from within ShowRestartWarning() as part of the deferred ShowRestartWarning. Now it executes directly in InitializeInEditor (before) code in ShowRestartWarning(). Hence why I asked if it still provides the same behavior or what the reason was for relocating it / changing the execution order.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It all is still in the same order, it may look a bit confusing just looking at the diffs, but the only thing I changed is outsourcing the logic of the prompt to a new private function called ShowRestartWarning()

@ritamerkl ritamerkl requested review from ekcoh and removed request for unity-cliff January 17, 2025 08:10
@ritamerkl ritamerkl merged commit 7b21b83 into develop Jan 17, 2025
3 of 77 checks passed
@ritamerkl ritamerkl deleted the backend-prompt-interrupts-asset-import branch January 17, 2025 15:58
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.

3 participants