@@ -471,7 +471,7 @@ public static InputActionAsset FromJson(string json)
471471 /// in the asset.
472472 /// </summary>
473473 /// <param name="actionNameOrId">Name of the action as either a "map/action" combination (e.g. "gameplay/fire") or
474- /// a simple name. In the former case, the name is split at the '/' slash and the first part is used to find
474+ /// a simple name e.g. "fire" . In the former case, the name is split at the '/' slash and the first part is used to find
475475 /// a map with that name and the second part is used to find an action with that name inside the map. In the
476476 /// latter case, all maps are searched in order and the first action that has the given name in any of the maps
477477 /// is returned. Note that name comparisons are case-insensitive.
@@ -491,6 +491,10 @@ public static InputActionAsset FromJson(string json)
491491 /// An exception is if, of the multiple actions with the same name, some are enabled and some are disabled. In
492492 /// this case, the first action that is enabled is returned.
493493 ///
494+ /// If an action name contains a slash "/", e.g. "yaw/pitch" and there is also a map called "yaw" which
495+ /// contains an action "pitch", the action "pitch" within the map "jump" will be returned instead of the
496+ /// action named "yaw/pitch".
497+ ///
494498 /// <example>
495499 /// <code>
496500 /// var asset = ScriptableObject.CreateInstance<InputActionAsset>();
@@ -533,28 +537,11 @@ public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = fals
533537
534538 if ( m_ActionMaps != null )
535539 {
536- // Check if we have a "map/action" path.
540+ // Check if we have a "map/action" path. If we do we either has a "map/action" path or a simple
541+ // action name containing a slash. We first attempt matching it to a "map/action" and only if that
542+ // fails do we attempt to search for a "some/action" name.
537543 var indexOfSlash = actionNameOrId . IndexOf ( '/' ) ;
538- if ( indexOfSlash == - 1 )
539- {
540- // No slash so it's just a simple action name. Return either first enabled action or, if
541- // none are enabled, first action with the given name.
542- InputAction firstActionFound = null ;
543- for ( var i = 0 ; i < m_ActionMaps . Length ; ++ i )
544- {
545- var action = m_ActionMaps [ i ] . FindAction ( actionNameOrId ) ;
546- if ( action != null )
547- {
548- if ( action . enabled || action . m_Id == actionNameOrId ) // Match by ID is always exact.
549- return action ;
550- if ( firstActionFound == null )
551- firstActionFound = action ;
552- }
553- }
554- if ( firstActionFound != null )
555- return firstActionFound ;
556- }
557- else
544+ if ( indexOfSlash >= 0 )
558545 {
559546 // Have a path. First search for the map, then for the action.
560547 var mapName = new Substring ( actionNameOrId , 0 , indexOfSlash ) ;
@@ -583,6 +570,23 @@ public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = fals
583570 break ;
584571 }
585572 }
573+
574+ // It's just a simple action name. Return either first enabled action or, if
575+ // none are enabled, first action with the given name.
576+ InputAction firstActionFound = null ;
577+ for ( var i = 0 ; i < m_ActionMaps . Length ; ++ i )
578+ {
579+ var action = m_ActionMaps [ i ] . FindAction ( actionNameOrId ) ;
580+ if ( action != null )
581+ {
582+ if ( action . enabled || action . m_Id == actionNameOrId ) // Match by ID is always exact.
583+ return action ;
584+ if ( firstActionFound == null )
585+ firstActionFound = action ;
586+ }
587+ }
588+ if ( firstActionFound != null )
589+ return firstActionFound ;
586590 }
587591
588592 if ( throwIfNotFound )
0 commit comments