Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by pixelf0x300 · Jan 09 at 05:44 PM · inputgamepadtooltipbinding

Input System: How do I get the key/button associated to Cancel[any]?

Hello, im trying to do an automatic tooltip system where you give the action and it splits interaction, button, action name, and considers if using controller or keyboard to give something similar to "Hold LeftShoulder to aim".

I wanted to do this system globally (that processes any binding you can put in the InputAction), but for the UI control scheme, as im using the Cancel [any], and Submit[any], the best i can get for those is the path "*/{Cancel}".

What im trying to achieve is to get for example in Cancel button: for Switch gamepad (Button South), For Playstation and Xbox controllers (Button East).

I can get this behaviour if I put the desired button to be canceled, but in that case the switch and xbox cancel wouldn't be different, and i wanted to keep that "automatic" behaviour.

Actually what i have to get the binding name and translate it to "button south" instead of "X" is

 InputControlPath.ToHumanReadableString(currentActionMap.action.bindings[currentActionMap.action.GetBindingIndexForControl(currentActionMap.action.controls[0])].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);

worth mentioning: i dont know if its a bug, but using left click for a binding gives index -1 in GetBindingIndexForControl().

I tried different combinations and methods to try get a string for the active controller that matched what im searching for but it either was empty, or it was the path mentioned above ( "*/{Cancel}" )

EDIT: about the index -1, it seems that it occurs in more scenarios, not only in left click. As i was writting the info about this problem I tought it hadn't anything to do with repeated bindings, but it seems it does. Lets say the Gameplay layer is first and the UI layer is second. If an action qith the binding in Q is set for both, the second in order will get index -1... I will investigate a little bit more about this. Seems weird to me because im passing the action, the controller, the index... The system shouldnt be confused to such point it thinks there's no binding to that action.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pixelf0x300 · Jan 09 at 11:05 PM

--------------------SEE EDIT BELOW-----------------

Okay, so i think i finally solved the two problems. Starting from the index problem I tried with some Debug.Log() and different methods from InputActionReference to get a string where the button asociated is the correct one.

The cleanest ones i got were .path and .tostring. Parsed with :

 InputControlPath.ToHumanReadableString(_stringToParse,InputControlPath.HumanReadableStringOptions.OmitDevice)

I get everything i wanted.

Also, I warn about this: if you use the Submit [Any] and want to display another key/button that is also asigned (for example: Spacebar instead of Enter), you have to put the [Any] Binding at the bottom of the action.

So an effective way to get the things done would be with this code:

//

 //
      // currenAction map is an InputActionReference
      var control = currentActionMap.action.controls[0];

      //Get the button binded to the given action. Translated in gamepad to a global scheme. 
      //Ex: Button South intead of X or B

      string buttonName = InputControlPath.ToHumanReadableString(control.path, InputControlPath.HumanReadableStringOptions.OmitDevice);

     //This segment fixes the first letter being lowercase
     // leftShift >> LeftShift
         if (!String.IsNullOrEmpty(buttonName))
     {
         buttonName = string.Concat(buttonName[0].ToString().ToUpper(), buttonName.Substring(1));
     }



This code gets the generic name: for gamepads it returns "ButtonSouth" for example. If you use a combined approach to get this strings, it would give weird results. In the main question, the code I provide gives "Button South", with spaces. take that in consideration.

To solve this problem, after all the code use the next one to add spaces between capital letters

         buttonName = Regex.Replace(buttonName, "([a-z])([A-Z])", "$1 $2");


EDIT: It seems that while i was testing if the [Any] binding gets also gamepads, it turns out the bindings had an specific button assigned for the action, it wasn't taking the automatic path I wanted. In keyboard it works fine, but when i try to get the button for a controller I get a null exception in currentActionMap.action.controls[0];...

At this point I think i cant get the automathic behaviour I want, and is more straight forward for players to have the same placing for the cancel/submit in controllers no matter if they are using nintendo's or xbox's.

I unmarked this answer as valid, I will try to get it working, and update the info if I manage to do it, and open again to other users to find the correct answer.

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

205 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

New input system, problem with rebinding 1 Answer

SteamVR 2.2 How to set custom input bindings without having a headset connected? 0 Answers

Cinemachine Freelook Camera Movement with Joystick 3 Answers

New Input System not detecting PS4 Gamepads 0 Answers

Gamepad input in UI stop working after a new panel cover the first one 0 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