@@ -260,11 +260,23 @@ void CleanUp()
260
260
{
261
261
m_RebindOperation ? . Dispose ( ) ;
262
262
m_RebindOperation = null ;
263
- action . Enable ( ) ;
263
+
264
+ action . actionMap . Enable ( ) ;
265
+ m_UIInputActionMap ? . Enable ( ) ;
264
266
}
265
267
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 ( ) ;
268
280
269
281
// Configure the rebind.
270
282
m_RebindOperation = action . PerformInteractiveRebinding ( bindingIndex )
@@ -329,6 +341,8 @@ protected void OnEnable()
329
341
s_RebindActionUIs . Add ( this ) ;
330
342
if ( s_RebindActionUIs . Count == 1 )
331
343
InputSystem . onActionChange += OnActionChange ;
344
+ if ( m_DefaultInputActions != null && m_UIInputActionMap == null )
345
+ m_UIInputActionMap = m_DefaultInputActions . FindActionMap ( "UI" ) ;
332
346
}
333
347
334
348
protected void OnDisable ( )
@@ -398,6 +412,12 @@ private static void OnActionChange(object obj, InputActionChange change)
398
412
[ SerializeField ]
399
413
private Text m_RebindText ;
400
414
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
+
401
421
[ Tooltip ( "Event that is triggered when the way the binding is display should be updated. This allows displaying "
402
422
+ "bindings in custom ways, e.g. using images instead of text." ) ]
403
423
[ SerializeField ]
0 commit comments