Skip to content

Commit 5ecee3e

Browse files
authored
FIX: ISXB-895 Fixed an issue where InputActionAsset.FindAction would unexpectedly throw System.NullReferenceException. (#1937)
* FIX: Fixed an issue where InputActionAsset.FindAction would throw even if throwIfNotFound is false.
1 parent 45bad64 commit 5ecee3e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7861,6 +7861,19 @@ public void Actions_CanLookUpMapInAssetById_UsingOldBracedFormat()
78617861
Assert.That(asset.FindActionMap($"{{{Guid.NewGuid().ToString()}}}"), Is.Null);
78627862
}
78637863

7864+
[Test]
7865+
[Category("Actions")]
7866+
[Description("ISXB-895 Can attempt to lookup non-existent action in asset by path")]
7867+
public void Actions_CanAttemptToLookUpNonExistentActionInAssetByPath()
7868+
{
7869+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
7870+
7871+
Assert.That(asset.FindAction("Map/Action1"), Is.Null);
7872+
7873+
var map = asset.AddActionMap("Map");
7874+
Assert.That(asset.FindAction("Map/Action1"), Is.Null); // ISXB-895 using a path to find non-existent (NullReferenceException)
7875+
}
7876+
78647877
[Test]
78657878
[Category("Actions")]
78667879
public void Actions_CanLookUpActionInAssetByName()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ however, it has to be formatted properly to pass verification tests.
1818
- Fixed prefabs and missing default control scheme used by PlayerInput component are now correctly shown in the inspector [ISXB-818](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-818).
1919
- Fixed error thrown when Cancelling Control Scheme creation in Input Actions Editor.
2020
- Fixed Scheme Name in Control Scheme editor menu that gets reset when editing devices [ISXB-763](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-763).
21+
- Fixed an issue where `InputActionAsset.FindAction(string, bool)` would throw `System.NullReferenceException` instead of returning `null` if searching for a non-existent action with an explicit action path and using `throwIfNotFound: false`, e.g. searching for "Map/Action" when `InputActionMap` "Map" exists but no `InputAction` named "Action" exists within that map [ISXB-895](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-895).
2122

2223
## [1.8.2] - 2024-04-29
2324

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,16 @@ public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = fals
570570
continue;
571571

572572
var actions = map.m_Actions;
573-
for (var n = 0; n < actions.Length; ++n)
573+
if (actions != null)
574574
{
575-
var action = actions[n];
576-
if (Substring.Compare(action.name, actionName,
577-
StringComparison.InvariantCultureIgnoreCase) == 0)
578-
return action;
575+
for (var n = 0; n < actions.Length; ++n)
576+
{
577+
var action = actions[n];
578+
if (Substring.Compare(action.name, actionName,
579+
StringComparison.InvariantCultureIgnoreCase) == 0)
580+
return action;
581+
}
579582
}
580-
581583
break;
582584
}
583585
}

0 commit comments

Comments
 (0)