In SendChatMessage() there is just a simple Debug.log(“SendChatMessage”);.
Whenever I click on the button, the event is fired, if I then click somewhere else, the event is fired again ( im not even clicking on the button this time, though this happens only if there is no other input in between ).
The first event is fired when I no longer press the mouse Button on the Button, so its a mouseUp event that fires it, the second time when I click somewhere else and the event is fired, It fires even though my finger is still pressing down the left mouse button.
Why is it firing twice and is there a way to somehow get additional information about the event? Another question: How can I make it already fire when pressing down the mouse button?
I found the problem.
On my Input Settings I had “mouse 0” for Submit.
So whenever I click on the button it fires the event and also selects the Button. If I then click somewhere else then a Submit is triggered, so the event gets called again. Simply removing “mouse 0” as positive Button for Submit for now and everything works fine ;).
Oh … my… God… haha, I’m facing the exactly same issue and when I saw your solution I couldn’t believe, in my case I was setting the submit button and cancel button from the Event System to Fire1 and Fire2! Thanks a bunch, I would never figure this out by myself!
OMG i sat 8 HOURS on this problem and couldnt figure it out. 8 HOURS. Do you know the feeling you get when you sit 8 hours on an error and then finally find the solution…
You saved my life with that “I found the problem.” 3 DAYs thinking what’s wrong with the code when the error was in the input manager. WTF thanks a lot
Likewise! @teremy , you’re probably long gone, but we from the future thank you in the past for kindly documenting this obscure problem. You have saved me (and many others, apparently) a lot of time!
I had the same issue. What I did is, I changed the button. It worked for me. It might be some unity bug. The same event worked for different button firing only once.
Give This solution a try. Maybe it will work for you too.
Aight, have the same problem. Not my fault tho. I’m using the Unity input system and have the simulated touchscreen enabled. Now my button events get fired for the simulated touch and for my mouse click. Disableing the mouse device in the editor doesn’t work either since it can’t simulate the touches then.
Does anyone have a solution which isn’t adding a new section two my Input Asset which simulates the touches or checking with a bool that every button can be only pressed once in a short amount of time?
Edit: It calls the OnClick event twice instantly when I click the button once.
Fixed it quite quickly. I double clicked the “DefaultInputAction” asset which is the “Action Asset” on the EventSystems “InputSystemUIInputModule”. This brings up the Input Asset for “Player” and “UI”. In UI, search for the “Point” Action and delete the “Position [Mouse]” binding.
In case you want to have it back at some point, “/position” is the path.
Hope it helps
UPDATE: Problem with that is, you can’t have buttons in the absolute lower left corner. I think it’s because it crosses the 0, 0 screen position then and there is a pointer lying around there.
Didn’t test it with a touch screen. But you might be allowed to put a button there if you are using one.
Just leaving this here in case someone else did the same stupid mistake as me -
I had set up the button to use animations, and each animation triggered an Animation Event in the first frame. The reason I experienced onClick executing multiple times is because I had created a ‘void Press()’ method that the Animation Event invoked, but I did not consider that the UI.Button class uses a ‘Press’ method internally to trigger the event, meaning I got the onClick from actually pressing, but then also from the Animation Event