2
\$\begingroup\$

I have a turn based roguelike with input issues that are driving me nuts.

I use the Unity Input/GetAxis() for keyboard input. I recently added a skill bar with clickable buttons that pass an int parameter to a simple class when clicked.

The problem I am having is that the OnClick() event, on the last button that was clicked, fires whenever the SPACE bar is pressed.

What could cause this? I do not have space set on any of the input Axes (I did originally and both the axes attached to SPACE and the OnClick() would fire)

Edit: The code is below. It is called by the OnClick() handler on the button in the inspector. If you run the project and press SPACE nothing happens. Then if you click a button the Debug.Log fires. Then press SPACE again and the debug fires again with the same button number as was last clicked.

public class SkillClickNotifier : MonoBehaviour
{
    [HideInInspector]
    public int SkillClicked;

    public void ButtonClicked(int skill)
    {
        Debug.Log("Button Clicked: "+ skill);
        // SkillClicked = skill;
        // GameManager.Notifications.PostNotification(this, "SkillClicked");
    }
}
\$\endgroup\$
  • \$\begingroup\$ I should probably note that I have been able to be certain that it is not my input system as the OnClick() is firing from Unity. I'm wondering if there is a setting or something I was unable to find with Google \$\endgroup\$ – Mike B Sep 20 '16 at 20:23
  • \$\begingroup\$ Post your input code. \$\endgroup\$ – jgallant Sep 20 '16 at 20:41
  • \$\begingroup\$ I finally found the answer. It was the Navigation property on the button. I thought it just had to do with a Tab order but it allows for keyboard Mouse Input \$\endgroup\$ – Mike B Sep 20 '16 at 21:15
  • \$\begingroup\$ Do you have a canvas with a eventsystem? \$\endgroup\$ – Leo Sep 20 '16 at 21:31
  • \$\begingroup\$ Yes, all UI controls are on a Canvas with an Event System \$\endgroup\$ – Mike B Sep 20 '16 at 22:18
1
\$\begingroup\$

I found the answer and am answering it myself in the hope it will help someone in the future.

In the Unity Button control there is a property called Navigation that defaults to Automatic. This is to allow keyboard navigation and was causing my issue when the Space bar was pressed. The correct setting for me was None.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You can also remap the "Submit" button in the Input Manager so space won't be used for keyboard navigation, in case you want to retain keyboard nav for menus with enter/return as your submit action. \$\endgroup\$ – DMGregory Sep 20 '16 at 22:20
  • \$\begingroup\$ OMG I went through all the inputs with a fine toothed comb and still missed the alt-positive on Submit being space... Thanks \$\endgroup\$ – Mike B Sep 21 '16 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.