Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by artie · Oct 31, 2013 at 02:52 AM · inputaxisinputmanager

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bluntweapon · Sep 17, 2014 at 06:05 PM 0
Share

What would be the point? Axes can't be dynamically added, so just keep a list of it somewhere in your application.

4 Replies

· Add your reply
  • Sort: 
avatar image
5

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image guavaman · Jul 21, 2015 at 05:55 PM 1
Share

Great post! It should be noted that this only works in the editor, not in a build.

avatar image ModLunar · Aug 04, 2017 at 12:25 AM 0
Share

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!

avatar image Bunny83 · Aug 04, 2017 at 01:08 AM 1
Share

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.

avatar image Sarkahn Bunny83 · Aug 05, 2017 at 04:11 PM 0
Share

True, I will edit my answer to clarify that.

avatar image
-1

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image glantucan · Sep 07, 2014 at 04:14 PM 0
Share

$$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.

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges