Skip to content

Commit 934f197

Browse files
FIX: "ArgumentNullException: Value cannot be null." when deleting a newly created input action (ISXB-1405) (#2129)
1 parent b5e3ca1 commit 934f197

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ however, it has to be formatted properly to pass verification tests.
1010

1111
## [Unreleased] - yyyy-mm-dd
1212

13+
### Fixed
14+
- Fixed an issue where removing a newly created action in the Asset Editor would cause an exception. [UUM-95693](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-95693)
15+
1316
## [1.13.0] - 2025-02-05
1417

1518
### Fixed

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Commands/Commands.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public static Command DeleteAction(int actionMapIndex, string actionName)
453453
return (in InputActionsEditorState state) =>
454454
{
455455
var actionMap = Selectors.GetActionMapAtIndex(state, actionMapIndex)?.wrappedProperty;
456-
var action = Selectors.GetActionInMap(state, actionMapIndex, actionName).wrappedProperty;
456+
var action = Selectors.GetActionInMap(state, actionMapIndex, actionName)?.wrappedProperty;
457457
var actionIndex = action.GetIndexOfArrayElement();
458458
var actionID = InputActionSerializationHelpers.GetId(action);
459459
var isCut = state.IsActionCut(actionMapIndex, actionIndex);
@@ -638,10 +638,17 @@ public static Command ChangeActionName(int actionMapIndex, string oldName, strin
638638
return (in InputActionsEditorState state) =>
639639
{
640640
var actionMap = Selectors.GetActionMapAtIndex(state, actionMapIndex)?.wrappedProperty;
641-
var action = Selectors.GetActionInMap(state, actionMapIndex, oldName).wrappedProperty;
642-
InputActionSerializationHelpers.RenameAction(action, actionMap, newName);
643-
state.serializedObject.ApplyModifiedProperties();
644-
state.m_Analytics?.RegisterActionEdit();
641+
var action = Selectors.GetActionInMap(state, actionMapIndex, oldName)?.wrappedProperty;
642+
// In an Asset Editor workflow, the serialized property might not exist in case a new action is created
643+
// that is yet to be named, and it's deleted before it's named.
644+
// This is a particular case when ActionTreeView::DeleteItem triggers
645+
// Focus callback -> OnEditTextFinished -> ChangeActionName.
646+
if (action != null)
647+
{
648+
InputActionSerializationHelpers.RenameAction(action, actionMap, newName);
649+
state.serializedObject.ApplyModifiedProperties();
650+
state.m_Analytics?.RegisterActionEdit();
651+
}
645652
return state;
646653
};
647654
}

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/Selectors.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,17 @@ public static SerializedProperty GetActionForIndex(SerializedProperty actionMap,
152152
return actionMap.FindPropertyRelative(nameof(InputActionMap.m_Actions)).GetArrayElementAtIndex(actionIndex);
153153
}
154154

155-
public static SerializedInputAction GetActionInMap(InputActionsEditorState state, int mapIndex, string name)
155+
public static SerializedInputAction? GetActionInMap(InputActionsEditorState state, int mapIndex, string name)
156156
{
157-
return new SerializedInputAction(state.serializedObject
157+
SerializedProperty property = state.serializedObject
158158
?.FindProperty(nameof(InputActionAsset.m_ActionMaps))?.GetArrayElementAtIndex(mapIndex)
159159
?.FindPropertyRelative(nameof(InputActionMap.m_Actions))
160-
?.FirstOrDefault(p => p.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue == name));
160+
?.FirstOrDefault(p => p.FindPropertyRelative(nameof(InputAction.m_Name)).stringValue == name);
161+
162+
// If the action is not found, return null.
163+
if (property == null)
164+
return null;
165+
return new SerializedInputAction(property);
161166
}
162167

163168
public static SerializedInputBinding GetCompositeOrBindingInMap(SerializedProperty actionMap, int bindingIndex)

0 commit comments

Comments
 (0)