Skip to content

Commit 156bd1f

Browse files
author
Dmytro Ivanov
authored
FIX: Handling InputActionAsset in InputActionTrace (#1543)
1 parent 573f4ff commit 156bd1f

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,8 +2004,6 @@ public void Actions_CanCreateActionsWithoutAnActionMap()
20042004
[Category("Actions")]
20052005
public void Actions_CanCreateActionAssetWithMultipleActionMaps()
20062006
{
2007-
var gamepad = InputSystem.AddDevice<Gamepad>();
2008-
20092007
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
20102008

20112009
var map1 = new InputActionMap("map1");
@@ -2042,6 +2040,8 @@ public void Actions_CanCreateActionAssetWithMultipleActionMaps()
20422040
// Enable only map1.
20432041
map1.Enable();
20442042

2043+
// Creating gamepad after maps are enabled to test trace catching binding resolve. Case ISXB-29.
2044+
var gamepad = InputSystem.AddDevice<Gamepad>();
20452045
Set(gamepad.leftStick, new Vector2(0.123f, 0.234f), startTime + 0.123);
20462046

20472047
// map1/action1 should have been started and performed.

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests.
1515
- Fixed `{fileID: 0}` getting appended to `ProjectSettings.asset` file when building a project ([case ISXB-296](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-296)).
1616
- Fixed `Type of instance in array does not match expected type` assertion when using PlayerInput in combination with Control Schemes and Interactions ([case ISXB-282](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-282)).
1717
- Fixed an InvalidOperationException when using Hold interaction, and by extension any interaction that changes to performed state after a timeout ([case ISXB-332](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-330)).
18+
- Fixed `Given object is neither an InputAction nor an InputActionMap` when using `InputActionTrace` on input action from an input action asset ([case ISXB-29](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-29)).
1819

1920
## [1.4.3] - 2022-09-23
2021

@@ -44,7 +45,7 @@ however, it has to be formatted properly to pass verification tests.
4445
## [1.4.1] - 2022-05-30
4546

4647
### Fixed
47-
- Fixed composite touchscreen controls were not firing an action if screen was touched before enabling the action ([case ISXB-98](https://jira.unity3d.com/browse/ISXB-98)).
48+
- Fixed composite touchscreen controls were not firing an action if screen was touched before enabling the action ([case ISXB-98](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-98)).
4849

4950
## [1.4.0] - 2022-04-10
5051

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionTrace.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private void UnhookOnActionChange()
438438
m_OnActionChangeHooked = false;
439439
}
440440

441-
private void OnActionChange(object actionOrMap, InputActionChange change)
441+
private void OnActionChange(object actionOrMapOrAsset, InputActionChange change)
442442
{
443443
// If we're subscribed to all actions, check if an action got triggered.
444444
if (m_SubscribedToAll)
@@ -448,8 +448,8 @@ private void OnActionChange(object actionOrMap, InputActionChange change)
448448
case InputActionChange.ActionStarted:
449449
case InputActionChange.ActionPerformed:
450450
case InputActionChange.ActionCanceled:
451-
Debug.Assert(actionOrMap is InputAction, "Expected an action");
452-
var triggeredAction = (InputAction)actionOrMap;
451+
Debug.Assert(actionOrMapOrAsset is InputAction, "Expected an action");
452+
var triggeredAction = (InputAction)actionOrMapOrAsset;
453453
var actionIndex = triggeredAction.m_ActionIndexInState;
454454
var stateForAction = triggeredAction.m_ActionMap.m_State;
455455

@@ -469,17 +469,20 @@ private void OnActionChange(object actionOrMap, InputActionChange change)
469469
if (change != InputActionChange.BoundControlsAboutToChange)
470470
return;
471471

472-
// Grab the associated action map.
473-
var action = actionOrMap as InputAction;
474-
InputActionMap actionMap;
475-
if (action != null)
476-
actionMap = action.m_ActionMap;
472+
// Grab the associated action map(s).
473+
if (actionOrMapOrAsset is InputAction action)
474+
CloneActionStateBeforeBindingsChange(action.m_ActionMap);
475+
else if (actionOrMapOrAsset is InputActionMap actionMap)
476+
CloneActionStateBeforeBindingsChange(actionMap);
477+
else if (actionOrMapOrAsset is InputActionAsset actionAsset)
478+
foreach (var actionMapInAsset in actionAsset.actionMaps)
479+
CloneActionStateBeforeBindingsChange(actionMapInAsset);
477480
else
478-
{
479-
actionMap = actionOrMap as InputActionMap;
480-
Debug.Assert(actionMap != null, "Given object is neither an InputAction nor an InputActionMap");
481-
}
481+
Debug.Assert(false, "Expected InputAction, InputActionMap or InputActionAsset");
482+
}
482483

484+
private void CloneActionStateBeforeBindingsChange(InputActionMap actionMap)
485+
{
483486
// Grab the state.
484487
var state = actionMap.m_State;
485488
if (state == null)

0 commit comments

Comments
 (0)