- Home /
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.
What would be the point? Axes can't be dynamically added, so just keep a list of it somewhere in your application.
Answer by Sarkahn · Jul 21, 2015 at 07:58 AM
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.
Great post! It should be noted that this only works in the editor, not in a build.
Thank you so much!! I always wanted to find a way to get a list of them, this is perfect for what I needed it for!
The answer is actually "no".
This solution does only work inside the editor and not in a build as it uses classes from the UnityEditor namespace. So this can't be used in your actual game, only inside editor scripts. Of course you can write an editor script which you would invoke once to store that information in an asset so it can be used at runtime.
Additionaly this "solution" uses reflection to access built-in classes and internal datafields. Those are not documented and therefore the internal structure can change without any warning between Unity releases which could break this solution.
Don't get me wrong, there's no real alternative out there since scripting support for the Input$$anonymous$$anager is long overdue. However it should be pointed out that this is actually a hacky workaround solution.
ps: they currently working on a new, better input system. However until it's ready to be included in a stable version you have to use the old one, at least in actual production builds.
Answer by RevolutionNow · Sep 07, 2014 at 11:39 AM
I'm not sure exactly how but I think that you need to use GetComponent and for loops :)
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
$$anonymous$$aybe I'm mistaken, but I don't think you really understand what the question is about. The Input$$anonymous$$anager is not a GameObjects Component. We are talking about the panel we get on the inspector when we select Edit -> Project Settings -> Input. And the question is what's the way to access its properties from a script, if there's one.
Answer by glantucan · Sep 01, 2014 at 06:34 AM
Hi, I'm strugling with same issue here. It would be really handy to be able to get that list from a script.
Answer by guavaman · Oct 03, 2014 at 03:11 AM
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.
Your answer
Follow this Question
Related Questions
Creating an input manager that supports axis 0 Answers
Weird Input Manager behaviour 1 Answer
Axis 9 and 10 not working in windows 10 0 Answers
Custom Input manager problem 0 Answers
Why is this script showing all keycodes except shift? 2 Answers