Get all the Input Action Reference from the Input Action Asset

Hello!
I was wondering if I can get all the Input Action Reference from the Input Action Asset, or if there is any way I can get them thru code.

Thanks :smile:

I am trying to do this as well, mostly to put the RebindUI sample to actual use on my own project. I’m trying to procedurally create a UI tab for each entry but can’t find a way to fill the ā€œInputActionReferenceā€ fields of the component.

I had the same need as you: I wanted to automate the creation of all my RebindActionUI in editor.

I finally get the list of the InputActionReference with:

Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(inputActionAsset));
List<InputActionReference> inputActionReferences = new List<InputActionReference>();
foreach (Object obj in subAssets) {
    // there are 2 InputActionReference returned for each InputAction in the asset, need to filter to not add the hidden one generated for backward compatibility
    if (obj is InputActionReference inputActionReference && (inputActionReference.hideFlags & HideFlags.HideInHierarchy) == 0) {
        inputActionReferences.Add(inputActionReference);
    }
}

where the variable inputActionAsset is an InputActionAsset from your assets. At the end of this snippet, the list inputActionReferences contains all the InputActionReference for this InputActionAsset.
It only works in the editor (uses AssetDatabase editor class).

On my side, I did this to instantiate the RebindActionUI from input system samples:

Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(inputActionAsset));
List<InputActionReference> inputActionReferences = new List<InputActionReference>();
foreach (Object obj in subAssets) {
    // there are 2 InputActionReference returned for each InputAction in the asset, need to filter to not add the hidden one generated for backward compatibility
    if (obj is InputActionReference inputActionReference && (inputActionReference.hideFlags & HideFlags.HideInHierarchy) == 0) {
        inputActionReferences.Add(inputActionReference);
    }
}

foreach (InputActionMap inputActionMap in inputActionAsset.actionMaps) {
    // here I also have an instantiation for the title of the action map

    foreach (InputAction inputAction in inputActionMap) {
        // match the action with the correct InputActionReference from the list created before
        foreach (InputActionReference inputActionReference in inputActionReferences) {
            if (inputActionReference.action == inputAction) {
                RebindActionUI rebindActionUI = Instantiate(rebindActionUIPrefab, transform);
                rebindActionUI.name = inputAction.name;
                rebindActionUI.actionReference = inputActionReference;
                rebindActionUI.rebindOverlay = rebindOverlay;
                if (inputAction.bindings.Count > 0) {
                    rebindActionUI.bindingId = inputAction.bindings[0].id.ToString();
                }
            }
        }
    }
}