- Home /
I created an UI button but click does not work.
Hi everybody, I'm trying to make a simple RestartGame Button for my game, the problem is that once I add the button I can't click on It, it's like it's disabled, I wrote my script for the button and everything but the button does not work, no click, no mouseover effect, nothing. Any Ideas?
It is good if you can post a screenshot of how your button's object inspectorvlooks like and the structure od your gameobject
Do I need to have one EventSystem object for each button I use? y added another button and I'm Having the same problem for the second one. The first one is fine but the second one is like it's disabled or something.
no, each scene only need 1 event system. how do you create youe button? if you right click > creare> ui> button it ahould automatically gen everything u need for you
hello all!! $$anonymous$$y buttons still not work. I have canvas, event system. but nothing happens when i hover my mouse over the buttons.. plz help.. also i have tried all answers including @Bored$$anonymous$$ormon
I didn't see anyone mentioning that so maybe this will help:
On your button object you have Button(Script) component
In the component there is On Click() "window"
Press + in the bottom-right corner
Drag your script to place for object
From dropdown list select your script and choose which function should activate when you click your button
I hope I understood question correctly and that you will understand my answer as I'm not the best english speaker :)
Answer by Kiwasi · Jan 31, 2015 at 02:52 AM
For a button to work you need the following in your scene
A button that is a child of a canvas object
The canvas object must have a GraphicRaycaster component
There must be an EventSystem object somewhere in your hierarchy.
Unity will build all this automatically if you create your button from the GameObject menu. But not if you add a button component manually.
The EventSystem object wasn't in my hierarchy, I Added it and my button works fine, thanks a lot.
It's also worth noting that if you somehow have 2 event systems in your scene the buttons will also stop working. You get a yellow warning message but it's easily missed.
I get this issue at new Unity 5 project. Restart ide and issue is dissapear.
When you create a UI element, it will add an EventSystem and the GraphicRaycaster. In my case I did not use the "usual way". Thanks to you my friend :)
Also, theres shouldnt be any additional colliders on a button.
Answer by remption · Feb 02, 2016 at 05:32 PM
In addition to BoredMormon's answer: If you have multiple Canvases, you may need to specify the Sort Order for each (or some) in their Canvas components
For example, I had a HUD Canvas that's always present, and a Paused Canvas that is active when the game is paused. I had to set the Paused Canvas SortOrder to be higher, so that it's "in front" of the HUD. Otherwise, the raycast would hit the HUD Canvas first, and wouldn't register with the Paused Canvas's buttons.
this was my problem. I have resolved that now, but do you think it is a good idea to have multiple canvases set up in a single game?
I have many as I have been using different and more complex animations on each canvas individually.
I tried to use panels initially to animate an overlapping animation making certain buttons available and others greyed out in the background, but the overlapping of the panels was not working out properly, so I set these objects on individual canvases and used a canvas group sorting layer option ins$$anonymous$$d.
any thoughts?
Additionally, a frequent error I make that brings me back here is sometimes I have a canvas childed to the main canvas. I don't know why or how I would do this on accident. But, that child canvas is unnecessary AND if the child doesnt have a graphic raycaster, it will not function. So check your hierarchies!
Answer by webspawn · Jan 28, 2016 at 01:29 PM
Hi, I don't know why but my EventSystem was with the option Force Module Active unchecked, when I checked this option my button works.
With adding the Graphic Raycaster
this solved my problem. Thank you!
Answer by Mohobie · Sep 19, 2015 at 08:52 PM
I recently encountered a loss of my working modal. I found that it was due to the mouse being locked by another script that made my click not actually fire on the button. Just a thought for anyone who might be looking.
If the mouse pos is locked, how do we unlock the mouse position?
This was the problem for me, adding Cursor.lockState = CursorLockMode.None;
to the pause state of my script unlocked the mouse and fixed the issue.
Answer by SnStarr · Jan 31, 2015 at 05:52 AM
@BoredMormon is correct, but if it is still not working, might I add that you also need to add a using statement to your script: using UnityEngine.EventSystem;
In my game, I have a menu with several butt(6th ,7th, 8th) they just not work. I dont know what happen. I even I duplicate from the working button, they still not work.
I found the problem. I have another gameobject with text component invisible, but not deactivate at the same location, not in the save parent . So when i hover over it. it select the other game object but not the button i have. Now i deactivate it. it work just fine
This was similar to my issue. Your observations helped me find the issue, Thanks. I had a dynamically sized text area that covered part of the button. I changed the order in the Hierarchy panel, and now all is well.
Your answer
Follow this Question
Related Questions
Cannot click UI button. 4 Answers
Can't to get Button script from gameobject in unity 0 Answers
How to play a sound for a Game Jam Menu Template button 0 Answers
SDK to create playback? 0 Answers
set angle on y Camera no sphere 0 Answers