@@ -260,11 +260,23 @@ 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+ // An "InvalidOperationException: Cannot rebind action x while it is enabled" will
269+ // be thrown if rebinding is attempted on an action that is enabled.
270+ //
271+ // On top of disabling the target action while rebinding, it is recommended to
272+ // disable any actions (or action maps) that could interact with the rebinding UI
273+ // or gameplay - it would be undesirable for rebinding to cause the player
274+ // character to jump.
275+ //
276+ // In this example, we explicitly disable both the UI input action map and
277+ // the action map containing the target action.
278+ action . actionMap . Disable ( ) ;
279+ m_UIInputActionMap ? . Disable ( ) ;
268280
269281 // Configure the rebind.
270282 m_RebindOperation = action . PerformInteractiveRebinding ( bindingIndex )
@@ -329,6 +341,8 @@ protected void OnEnable()
329341 s_RebindActionUIs . Add ( this ) ;
330342 if ( s_RebindActionUIs . Count == 1 )
331343 InputSystem . onActionChange += OnActionChange ;
344+ if ( m_DefaultInputActions != null && m_UIInputActionMap == null )
345+ m_UIInputActionMap = m_DefaultInputActions . FindActionMap ( "UI" ) ;
332346 }
333347
334348 protected void OnDisable ( )
@@ -398,6 +412,12 @@ private static void OnActionChange(object obj, InputActionChange change)
398412 [ SerializeField ]
399413 private Text m_RebindText ;
400414
415+ [ Tooltip ( "Optional reference to default input actions containing the UI action map. The UI action map is "
416+ + "disabled when rebinding is in progress." ) ]
417+ [ SerializeField ]
418+ private InputActionAsset m_DefaultInputActions ;
419+ private InputActionMap m_UIInputActionMap ;
420+
401421 [ Tooltip ( "Event that is triggered when the way the binding is display should be updated. This allows displaying "
402422 + "bindings in custom ways, e.g. using images instead of text." ) ]
403423 [ SerializeField ]
0 commit comments