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: Fixed errors caused by recreation of DefaultInputActions instance in InputSystemProvider #2149

Merged
merged 2 commits into from
Mar 25, 2025

Conversation

Secticide
Copy link
Collaborator

Description

Fixes ISXB-1446

Errors similar to the following would be output when running playmode tests when using the InputTestFixture (with domain reloads on playmode entry turned off):

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputActionState+BindingState.get_actionIndex () (at ./Library/PackageCache/com.unity.inputsystem@e2c83221d2dc/InputSystem/Actions/InputActionState.cs:3443)
UnityEngine.InputSystem.InputActionState.ProcessControlStateChange (System.Int32 mapIndex, System.Int32 controlIndex, System.Int32 bindingIndex, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr) (at ./Library/PackageCache/com.unity.inputsystem@e2c83221d2dc/InputSystem/Actions/InputActionState.cs:1442)
UnityEngine.InputSystem.InputActionState.UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (UnityEngine.InputSystem.InputControl control, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Int64 mapControlAndBindingIndex) (at ./Library/PackageCache/com.unity.inputsystem@e2c83221d2dc/InputSystem/Actions/InputActionState.cs:1343)
UnityEngine.InputSystem.InputManager.FireStateChangeNotifications (System.Int32 deviceIndex, System.Double internalTime, UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at ./Library/PackageCache/com.unity.inputsystem@e2c83221d2dc/InputSystem/InputManagerStateMonitors.cs:394)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)

This was caused by the recreation of a DefaultInputActions instance via InputSystemProvider.OnActionsChange.

This PR makes some adjustments to InputSystemProvider to only create a single DefaultInputActions instance that is reused. However, when listening for changes to actions - we still reselect the InputActionAsset used on every change.

I also noticed a bunch of things that could be cleaned up in the process and so made some modifications and renames to the class:

  • InputSystemProvider.Configuration was only holding the InputActionAsset, the action strings were constant. Since the InputActionAsset reference was removed - it made sense to switch it to being a static class.
  • There was a name mismatch between RegisterNextPreviousAction & UnregisterFixedActions and so RegisterNextPreviousAction has been renamed to RegisterFixedActions.
  • RegisterFixedActions & UnregisterFixedActions were being called on every action update, this is much more than required so they have been moved to Initialize and Shutdown respectively.

Testing status & QA

Tested locally using the project provided by the user.

Overall Product Risks

  • Complexity: 1
  • Halo Effect: 1

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.

@Secticide Secticide self-assigned this Mar 7, 2025
@ekcoh ekcoh requested a review from Pauliusd01 March 19, 2025 20:19
@ekcoh
Copy link
Collaborator

ekcoh commented Mar 19, 2025

Added @Pauliusd01 for QA perspective.

@Secticide Secticide force-pushed the isxb-1446/input-test-fixture-errors-fix branch from efc9dda to 85ed54d Compare March 20, 2025 14:14
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, checked the user project, made sure that UITK UI still works as expected in playmode and win player, project wide actions still work as expected, mentioned bugs in the comments (ISX-1954, ISXB-811) are still fixed

…de the action strings readonly and renamed the class 'Actions', Added reused DefaultInputActions field to InputSystemProvider and added new 'SelectInputActionAsset' method to select the input asset used (either project wide asset or default input actions), Renamed 'RegisterNextPreviousAction' to 'RegisterFixedActions' to better mirror method used to unregister these actions - moved these methods to be called in Initialize / Shutdown to avoid re-registering when not required, Simplified InputActionAssetVerifier.Verify now that configuration action strings are statically known (an instance of the struct is no longer required)
@Secticide Secticide force-pushed the isxb-1446/input-test-fixture-errors-fix branch from 85ed54d to 9fbe841 Compare March 25, 2025 09:52
@Secticide Secticide merged commit 1c21242 into develop Mar 25, 2025
110 checks passed
@Secticide Secticide deleted the isxb-1446/input-test-fixture-errors-fix branch March 25, 2025 14:47
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