Get list of Axes?

Is there a way to get the list of axes, or enumerate them somehow, defined in the InputManager? I know I can get them if I know there name. I want to get all the defined ones, to find their names and such.

Yup.

Edit: As pointed out by Bunny in the comments - this will only work in the editor and relies on reflection - it could easily break in future versions of Unity if they randomly decide to rename or restructure their input classes/data. However there is no real alternative with the existing (as of 2017.1) input system.

using UnityEngine;
using System.Collections;

using UnityEditor;

public class ReadInputManager
{
    public static void ReadAxes()
    {
        var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];

        SerializedObject obj = new SerializedObject(inputManager);

        SerializedProperty axisArray = obj.FindProperty("m_Axes");

        if (axisArray.arraySize == 0)
            Debug.Log("No Axes");

        for( int i = 0; i < axisArray.arraySize; ++i )
        {
            var axis = axisArray.GetArrayElementAtIndex(i);

            var name = axis.FindPropertyRelative("m_Name").stringValue;
            var axisVal = axis.FindPropertyRelative("axis").intValue;
            var inputType = (InputType)axis.FindPropertyRelative("type").intValue;

            Debug.Log(name);
            Debug.Log(axisVal);
            Debug.Log(inputType);
        }
    }

    public enum InputType
    {
        KeyOrMouseButton,
        MouseMovement,
        JoystickAxis,
    };

    [MenuItem("Assets/ReadInputManager")]
    public static void DoRead()
    {
        ReadAxes();
    }

}

If you have a look at the Input Manager the rest should be pretty easy to figure out.

Hi, I’m strugling with same issue here. It would be really handy to be able to get that list from a script.

Nope, there’s no way to do it. Unity’s InputManager is extremely limited and doesn’t allow you do to anything at all during runtime except get input.

Update: Yes, it’s possible in the editor as Sarkhan’s post shows, but not in a game build.

I’m not sure exactly how but I think that you need to use GetComponent and for loops :slight_smile:

http://unity3d.com/learn/tutorials/modules/beginner/scripting/loops
http://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components

these two videos might help