Skip to content

Commit b087ccd

Browse files
committed
Fix InputForUI action lifecycle to only manage the UI action map.
1 parent 61807cc commit b087ccd

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ internal class InputSystemProvider : IEventProviderImpl
1717

1818
DefaultInputActions m_DefaultInputActions;
1919
InputActionAsset m_InputActionAsset;
20+
InputActionMap m_UIActionMap;
21+
bool m_ShouldDisableUIActionMapOnUnregister;
2022

2123
// Note that these are plain action references instead since InputActionReference do
2224
// not provide any value when this integration doesn't have any UI. If this integration
@@ -636,14 +638,11 @@ void RegisterActions()
636638
m_RightClickAction = FindActionAndRegisterCallback(Actions.RightClickAction, OnRightClickPerformed);
637639
m_ScrollWheelAction = FindActionAndRegisterCallback(Actions.ScrollWheelAction, OnScrollWheelPerformed);
638640

639-
// When adding new actions, don't forget to add them to UnregisterActions
640-
if (InputSystem.actions == null)
641-
{
642-
// If we've not loaded a user-created set of actions, just enable the UI actions from our defaults.
643-
m_InputActionAsset.FindActionMap("UI", true).Enable();
644-
}
645-
else
646-
m_InputActionAsset.Enable();
641+
// Only touch the UI map so we don't change the enabled state of unrelated maps.
642+
m_UIActionMap = m_InputActionAsset?.FindActionMap("UI", true);
643+
m_ShouldDisableUIActionMapOnUnregister = m_UIActionMap != null && !m_UIActionMap.enabled;
644+
if (m_ShouldDisableUIActionMapOnUnregister)
645+
m_UIActionMap.Enable();
647646
}
648647

649648
void UnregisterAction(ref InputAction action, Action<InputAction.CallbackContext> callback = null)
@@ -664,8 +663,11 @@ void UnregisterActions()
664663
UnregisterAction(ref m_RightClickAction, OnRightClickPerformed);
665664
UnregisterAction(ref m_ScrollWheelAction, OnScrollWheelPerformed);
666665

667-
if (m_InputActionAsset != null && m_InputActionAsset != InputSystem.actions)
668-
m_InputActionAsset.Disable();
666+
if (m_ShouldDisableUIActionMapOnUnregister && m_UIActionMap != null)
667+
m_UIActionMap.Disable();
668+
669+
m_UIActionMap = null;
670+
m_ShouldDisableUIActionMapOnUnregister = false;
669671
}
670672

671673
void SelectInputActionAsset()

0 commit comments

Comments
 (0)