Skip to content

Commit 371ae05

Browse files
committed
Check for dangling action references in Inspector and set them to "None"
A dangling action reference means a actin reference that point to a non-existent InputAction. This needs to be checked here in case an input action is removed from the project-wide actions asset. Otherwise the UI will still hold on to a dangling action reference.
1 parent 9d20997 commit 371ae05

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionReferencePropertyDrawer.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,32 @@ internal sealed class InputActionReferencePropertyDrawer : PropertyDrawer
1515
{
1616
private readonly SearchContext m_Context = UnityEditor.Search.SearchService.CreateContext(new[]
1717
{
18-
AssetSearchProviders.CreateInputActionReferenceSearchProviderForAssets(),
19-
AssetSearchProviders.CreateInputActionReferenceSearchProviderForProjectWideActions(),
18+
InputActionReferenceSearchProviders.CreateInputActionReferenceSearchProviderForAssets(),
19+
InputActionReferenceSearchProviders.CreateInputActionReferenceSearchProviderForProjectWideActions(),
2020
}, string.Empty, SearchConstants.PickerSearchFlags);
2121

2222

2323
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
2424
{
25+
// Sets the property to null if the action is not found in the asset.
26+
ValidatePropertyWithDanglingInputActionReferences(property);
27+
2528
ObjectField.DoObjectField(position, property, typeof(InputActionReference), label,
2629
m_Context, SearchConstants.PickerViewFlags);
2730
}
31+
32+
static void ValidatePropertyWithDanglingInputActionReferences(SerializedProperty property)
33+
{
34+
if (property?.objectReferenceValue is InputActionReference reference)
35+
{
36+
var action = reference?.asset?.FindAction(reference.action.id);
37+
if (action is null)
38+
{
39+
property.objectReferenceValue = null;
40+
property.serializedObject.ApplyModifiedProperties();
41+
}
42+
}
43+
}
2844
}
2945
}
3046

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void OnActivate(string searchContext, VisualElement rootElement)
3535
// Note that focused element will be set if we are navigating back to
3636
// an existing instance when switching setting in the left project settings panel since
3737
// this doesn't recreate the editor.
38-
if (m_RootVisualElement.focusController.focusedElement != null)
38+
if (m_RootVisualElement?.focusController?.focusedElement != null)
3939
OnEditFocus(null);
4040
}
4141

0 commit comments

Comments
 (0)