Unity-Technologies / InputSystem

An efficient and versatile input system for Unity.
Other
1.42k stars 306 forks source link

FIX: Exception thrown when acessing Action's bindings after changing Composite (ISXB-494) #1966

Closed timkeo closed 1 month ago

timkeo commented 1 month ago

Description

Fixes a corner-case bug where an exception is thrown when accessing an Action's bindings property after modifying a Composite binding. Although this scenario is covered by a test, the bug only occurs when the target action is contained by an ActionMap.

It's unclear exactly why an action in a Map is handled differently than one that isn't, due to the complex functionality of Adding/Updating bindings, and there might be other cases this issue (or something similar) can occur. However, I decided a simple, low-risk fix is preferable to a more fundamental change.

Changes made

Added an Action initializer when creating a new Binding within BindingSyntax.InsertPartBinding(). Added a new test to cover this scenario: Actions_CanChangeBindingPart_ToExistingCompositeInActionMap()

NOTE: The new test is nearly identical to the existing Actions_CanAddBindingsToActions_ToExistingComposite() test except the target action is added to an ActionMap.

Testing

Verified the bug fix, both manually with the customer's repro project and with the new test case.

Risk

Very low-risk change: worst case Action reference is null and we fallback to existing behavior.

Checklist

Before review:

During merge:

After merge: