@@ -260,11 +260,21 @@ void CleanUp()
260260 {
261261 m_RebindOperation ? . Dispose ( ) ;
262262 m_RebindOperation = null ;
263- action . Enable ( ) ;
263+
264+ action . actionMap . Enable ( ) ;
265+ m_UIInputActionMap ? . Enable ( ) ;
264266 }
265267
266- //Fixes the "InvalidOperationException: Cannot rebind action x while it is enabled" error
267- action . Disable ( ) ;
268+ // When rebinding an action, it is good practice to disable the action itself.
269+ //
270+ // Here, we are disabling the entire action map in which the action resides.
271+ // It is recommended to organise your action maps such that a "Gameplay" action map
272+ // which contains the rebindable actions. This map can then be disabled while the
273+ // rebinding UI is on display.
274+ //
275+ // Also prevents "InvalidOperationException: Cannot rebind action x while it is enabled" errors.
276+ action . actionMap . Disable ( ) ;
277+ m_UIInputActionMap ? . Disable ( ) ;
268278
269279 // Configure the rebind.
270280 m_RebindOperation = action . PerformInteractiveRebinding ( bindingIndex )
@@ -329,6 +339,8 @@ protected void OnEnable()
329339 s_RebindActionUIs . Add ( this ) ;
330340 if ( s_RebindActionUIs . Count == 1 )
331341 InputSystem . onActionChange += OnActionChange ;
342+ if ( m_DefaultInputActions != null && m_UIInputActionMap == null )
343+ m_UIInputActionMap = m_DefaultInputActions . FindActionMap ( "UI" ) ;
332344 }
333345
334346 protected void OnDisable ( )
@@ -398,6 +410,12 @@ private static void OnActionChange(object obj, InputActionChange change)
398410 [ SerializeField ]
399411 private Text m_RebindText ;
400412
413+ [ Tooltip ( "Optional reference to default input actions containing the UI action map. The UI action map is "
414+ + "disabled when rebinding is in progress." ) ]
415+ [ SerializeField ]
416+ private InputActionAsset m_DefaultInputActions ;
417+ private InputActionMap m_UIInputActionMap ;
418+
401419 [ Tooltip ( "Event that is triggered when the way the binding is display should be updated. This allows displaying "
402420 + "bindings in custom ways, e.g. using images instead of text." ) ]
403421 [ SerializeField ]
0 commit comments