Disable UI Button clicks
Hi there. This question seems like a longshot to ask but figured what the heck.
I have a UI Panel with a collection of Button objects on it. The goal is to be able to navigate up and down and click the selected button with only a game controller. There can be multiple controllers attached so only the game controller being 'ListendTo' should operate the panel.
So far, everything is working as designed. I am getting the array of Button objects on the panel, and I can navigate up and down the button group with the correct controller. Any other controller has no navigation effect. In otherwords, Player1 can navigate the buttons, Player2 has no control.
To fire a button click I use;
if (mLocalInput.ButtonPressed(Submit)) // Executes the Press
ExecuteEvents.Execute(selectedButton.gameObject, eventSystem, ExecuteEvents.pointerDownHandler);
'mLocalInput' is the controller being listened to. So far it's working well for the selected controller.
The problem is that the buttons are also still receiving click events from all other devices. Other controllers and the mouse can still fire the click event for the selected button. In otherwords, Player1 can navigate and click buttons, Player2 can't navigate but can still click buttons.
I've come to the conclusion that Buttons have some sort of method of listening to all left Click or 'Submit' button events.
Is there a way to disable the default button click events for buttons?
Hopefully that makes sense. thanks David
Answer by corn · Jan 04, 2016 at 05:24 PM
Not entirely sure that's what you're looking for, but you can use Button.interactable, set it to false and your button won't be clickable.
Thanks, I'd thought of that. Unfortunately that grey's out the button and ignores the ExecuteEvents call.
I need something that will still handle my event calls, but ignores input from any devices other than the device it should be listening to.
How about something like that then ?
if (mLocalInput.ButtonPressed(Submit))
{
selectedButton.interactable = true;
// Executes the Press
ExecuteEvents.Execute(selectedButton.gameObject, eventSystem, ExecuteEvents.pointerDownHandler);
selectedButton.interactable = false;
}
That's kind of a workaround, but only the controller being listened to will be able to click the button.
Not exactly correct, but maybe something to work with. It still greys out the button that's not selected but I might be able to get creative with textures to work around that.
I don't know, Unity's input system seems like it was designed around single player games. As soon as you have more than one controller I seem to be writing a lot of work arounds. The "Re-Wired" component from the Asset Store helps a lot to manage and listen to multiple controllers, but the UI interaction is still a bit of an issue, because the components listen to any device by default. I'm sure there's probably a way to do this.
Your answer
![](https://koobas.hobune.stream/wayback/20220612054826im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
If Mouse cursor is above an object, start animation (without click on It) 2 Answers
how to make a main menu button 0 Answers
Buttons only work occasionally. 0 Answers
Cannot assign variable agents for clicking a button 0 Answers
after pressing button many times the player starts moving more. 1 Answer