Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[Solved] UI Button not working at all

Discussion in 'UGUI & TextMesh Pro' started by Sargaxon, Aug 25, 2016.

  1. Sargaxon

    Sargaxon

    Joined:
    Aug 20, 2016
    Posts:
    23
    My button won't even highlight on mouse over.

    I have an EventSystem.
    Tried with the EventSystem option Force Module Active.
    I have only one Canvas.
    The Canvas has a Graphic Raycaster component.
    Canvas Render Mode is set to Screen Space - Overlay, also tried the other two with the camera, didn't work.
    The button is a child object of the Canvas.
    The button is marked as interactable and calls a function from a script.
    There are no other HUD objects that are at the same place as the button.
    I've added using UnityEngine.EventSystem; to my script.
    Tried putting the button on different places in the hierarchy.
    Tried playing the game and restarting Unity a couple of times.

    There are a few more things I've tried for sure, can't remember everything at the moment.. getting desperate already.
     
    silviubogan, fjyuan and aboazar like this.
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    don't the raycasters go on the camera? not sure if that's an issue or you just need one in the scene...
     
    jamestp3 likes this.
  3. Sargaxon

    Sargaxon

    Joined:
    Aug 20, 2016
    Posts:
    23
    Hmm not sure, tried it now, if I add a Graphic Raycaster to the Camera component, it adds a Canvas component too, which should be on the Canvas GameObject. Also tried variations with this, changing the camera render mode with the Raycaster on Camera, no success once again..
     
  4. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    What version of Unity, what OS are you building for? It often helps to narrow down the problem by stripping away everything then slowly adding things back. I would create a new empty test project. Add UI Button to the scene, it should automatically add a Canvas and an Event System. Then Create an Empty Game Object that is a root object in the hierarchy. Create a Script with one Public function called TestButton that just calls Debug.Log("I'm pressed"). Attach it to your GameObject, then attach the Button's OnClick to that Function in the editor. Play and press the button and see if you get the Debug Log in the console. I suspect you will.

    I'd do all the above with the default settings Unity has for everything. Then change the settings to what your project has. Possibly adding more items and objects from your scene until it stops working.
     
  5. Sargaxon

    Sargaxon

    Joined:
    Aug 20, 2016
    Posts:
    23
    After a long time I managed to find the problem, although it was already wrong in the tutorials default settings.

    If anyone else will have a similar problem, select your Canvas GameObject and look at it's components. I had the following:
    Canvas, Canvas Scaler, Graphic Raycaster, Canvas Group etc..
    Select the Canvas Group component and check the boxes of "Interactable" and "Block Raycasts". It works like a charm now. Thanks everyone for your effort.
     
    Shams2280, Aoisa, winter2007d and 5 others like this.
  6. brigosx

    brigosx

    Joined:
    May 21, 2013
    Posts:
    6
    Hi to all,

    I am using Unity 5.5.2 Personal and I've recently created a start up scene for my project. I've just put 2 UI buttons for which Unity has created a Canvas GameObject. The UI buttons are child of this Canvas.

    What I've noticed is that by default the Canvas GameObject was created without the raycaster and group components (I don't remember if there was a scaler component at the initiation of the GameObject).

    The solution for me was to add the 2 missing raycaster and group components with their default values (the 2 checkboxes that Sargaxon mentioned above).

    Maybe my fault was that I've initially created a UI Image and a UI Text object making Unity to create the Canvas without these components. I really don't know.
     
  7. vinay_vidhani

    vinay_vidhani

    Joined:
    Oct 27, 2016
    Posts:
    9
    I had this problem too, I solved my issue by enabling the Raycast Target check box in Image(Script) (button's Inspector)
     
    dumanski738 and ow3n like this.
  8. LeopardX

    LeopardX

    Joined:
    May 31, 2015
    Posts:
    63
    I had this same problem though it was none of the above, i fixed mine cause i had a compile error not haveing horizontal and verticle in the inputs..
     
  9. MurcsRoyce

    MurcsRoyce

    Joined:
    Jul 19, 2017
    Posts:
    38

    Good work! accidentally deleting a component and not knowing which one it was, caused the program to lock up its visual clickable functions. and re adding the component fixes it (Graphic Raycaster) thanks.
     
    ccoodduu likes this.
  10. __RIPstER__

    __RIPstER__

    Joined:
    Aug 4, 2015
    Posts:
    2
    So, I had everything working fine. I had my Title menu and game over menu working, but only after I tried to add a pause menu in it, it made only the buttons in the scene I tried to put the pause in stop working. The Title menu works fine, but it doesn't have a event system or canvas group. I tried copying all the components from the Title menu into that game scene but then they stopped working.
     
  11. __RIPstER__

    __RIPstER__

    Joined:
    Aug 4, 2015
    Posts:
    2
    ///UPDATE///
    After copying the title screen components into the game scene, even though I never altered the title components in the title screen (I just ctrl+c and ctrl+v the canvas into my game scene) they also stopped working. So now no buttons I use work. I have no clue whats wrong, because I didn't change anything, they just stopped working, and I made sure not to save, so I could go back and hard reset to my last save just in case, but after closing and reopening the project, none of the buttons work, even though Im opening from a file where they still worked.
     
  12. Ayfri

    Ayfri

    Joined:
    Jan 15, 2018
    Posts:
    2
    Me too ! Can you help us, and I want to do a restart button who restart the scene, what is the code for that please ?
     
  13. Hadrien

    Hadrien

    Joined:
    Sep 7, 2013
    Posts:
    25
    Same problem for me, as soon as I duplicate a button, all of the others buttons inside my Canvas stopped working… Does anyone have an idea to fix this?

    It's pretty annoying since I have to re-create all the buttons any time I want to add another one.
     
  14. Ayfri

    Ayfri

    Joined:
    Jan 15, 2018
    Posts:
    2
    Do you have your eventsystem, me I deleted it and that doesn't work... I create a new eventsystem and now all work !
     
    shalwasia0, orix_, JChilton and 7 others like this.
  15. dididucdich

    dididucdich

    Joined:
    Nov 29, 2016
    Posts:
    17
    HI,

    check your event system item in the editor hierarchy, inside some check boxes are disabled after duplicating an button (thats was the problem at my side).
     
    Heavensrain88, heglys and RoninGT like this.
  16. fasanom99

    fasanom99

    Joined:
    Feb 28, 2018
    Posts:
    1
    I have this problem, how i can adjust it?
     
  17. RoninGT

    RoninGT

    Joined:
    Apr 16, 2018
    Posts:
    10
    Good sir or madam! I could give you a kiss... You fixed a lot of my issues!!! Thanks!
     
  18. Jace-Xanthos

    Jace-Xanthos

    Joined:
    Nov 25, 2017
    Posts:
    2
    spent a good 20 minutes running through all the possibilities just to find that i had a 1000 by 1000 clear text object on the top layer that was blocking my button
     
    mdrunk likes this.
  19. meeruTheCoder

    meeruTheCoder

    Joined:
    Jul 13, 2018
    Posts:
    9
    I literally have the same exact problem with my game. Someone please help
     
  20. anileapen05

    anileapen05

    Joined:
    Jun 8, 2013
    Posts:
    83
    Same problem with buttons , it stopped responding.
     
  21. anileapen05

    anileapen05

    Joined:
    Jun 8, 2013
    Posts:
    83
    It worked only after removing and then attaching the button component and image component.
    Interestingly never had any issue with legacy GUI
     
  22. ayhaab-pasha

    ayhaab-pasha

    Joined:
    Dec 6, 2015
    Posts:
    5
    I was having this problem. I was developing an AR shooting game. The problem was that the Event System Game Object was moved in to Target Builder UI Game Object. I placed it outside, like it was not a child of any thing. And so the buttons started to work. Don't misplace Event System. Hope this helps.
     
    Link-in likes this.
  23. dillon_yeti

    dillon_yeti

    Joined:
    May 11, 2015
    Posts:
    9
    I had a similar problem and thought I would share my solution.

    I had a 'root' Canvas Game Object, which then had several child Canvas GameObjects.

    In order for the Buttons to work, the Button's direct parent Canvas must have Graphic Raycaster component. It's not enough that the root Canvas has one.

    Example:

    Code (JavaScript):
    1. Canvas1  // must have Graphic Raycaster for Button1 to work
    2.   Button1
    3.   SubCanvas1  // must have Graphic Raycaster for Button2 to work
    4.     Button2
    5.   SubCanvas2  // must have Graphic Raycaster for Button3 to work
    6.     Button3
     
    znickbar, sonnyb, ltomov and 3 others like this.
  24. Comafly

    Comafly

    Joined:
    May 30, 2014
    Posts:
    80
    This solved it for me. Thanks! I was losing the ability to press buttons after changing scenes. It was because the event system was being destroyed when loading a new scene. DontDestroyOnLoad() solved that easy enough.
     
    ayhaab-pasha likes this.
  25. BMarcia

    BMarcia

    Joined:
    Jul 5, 2018
    Posts:
    1
    the problem was on event system
     
    MaratG2, zhangvisual and ahmedsanad93 like this.
  26. game_genie

    game_genie

    Joined:
    Sep 22, 2017
    Posts:
    1
    Life saver. reading yours made me realized i needed to give the canvas a higher sort order
     
    KarlosKS likes this.
  27. FMisi

    FMisi

    Joined:
    Dec 28, 2018
    Posts:
    1
    In my case, the problem was in the hierarchy view.
    In the Canvas, I created a GameObject.
    The GameObject had 2 Button objects, and 3 another objects.
    The objects inside the GameObject were not in the appropriate order.
    Changing the order as it is in the scene worked for me.
     
  28. IbraheemAli

    IbraheemAli

    Joined:
    Dec 31, 2018
    Posts:
    3
    My hierarchy goes:

    CanvasMenu
    PanelMenu
    ButtonMainMenu
    ButtonRestart


    (I renamed the UI element to fit the project)
     
  29. eshwarerukulla1

    eshwarerukulla1

    Joined:
    Feb 5, 2019
    Posts:
    1
    Under Canvas in ur button check for interactable in the components
     
  30. zhangvisual

    zhangvisual

    Joined:
    Jul 11, 2018
    Posts:
    1
    I did exactly the same thing because I was pretty new to Unity months ago. EventSystem is very necessary to get the UI elements work correctly in Unity.
     
    schcui likes this.
  31. bordeianuadrian370

    bordeianuadrian370

    Joined:
    Jul 29, 2018
    Posts:
    1
    UI elements under Canvas objects are rendered according to their hierarchy. Objects at the bottom will be rendered on top. So move your button to the bottom of the Canvas hierarchy, maybe something it is blocking it. Also move the Event System to the top of the hierarchy
     
    Benfont likes this.
  32. heglys

    heglys

    Joined:
    Dec 4, 2018
    Posts:
    1
    OMG! You saved my life! I was almost exporting the whole project to a new one because suddenly buttons and scroll rects stop working and this answer was the best! I problably deleted it in some moment and I didn't realize it.
     
  33. Argi203

    Argi203

    Joined:
    Jul 17, 2019
    Posts:
    1
    In my case i accidently deleted event system and then just forgot about it . After 4 hours i finally found what was cousing the error.
     
  34. TouchedMoon728

    TouchedMoon728

    Joined:
    Aug 1, 2019
    Posts:
    1
    I F***ing love you
     
  35. marirenee123

    marirenee123

    Joined:
    Nov 26, 2018
    Posts:
    1
    BLESS YOU!! I have been trying to figure out why my UI didn't work for literally the last 2 days. You are a lifesaver!!!
     
  36. quares

    quares

    Joined:
    Oct 11, 2019
    Posts:
    1
    God swear I tried every f**king trick from the comments and nothing worked
     
    chikandduck likes this.
  37. rmills1997

    rmills1997

    Joined:
    Oct 12, 2019
    Posts:
    4
    Same maybe its a problem with a new version of Unity... Some scenes my buttons work and others they dont at all SO FRUSTRATING
     
  38. ffxiangyu

    ffxiangyu

    Joined:
    Dec 9, 2014
    Posts:
    4
    For my case just now, something (nearly) transparent is blocking the button.haha
     
  39. olegf2a

    olegf2a

    Joined:
    Dec 1, 2019
    Posts:
    1
    Works as charm, just added and all work :D
     
  40. lizzl

    lizzl

    Joined:
    Nov 15, 2019
    Posts:
    3
    Thanks a lot @takatok was struggling to get UI button working - no where i could find step by step for UI button. Was struggling the whole day to get button click working, your steps mentioned here helped me. Thanks
     
  41. liveswithoutfear

    liveswithoutfear

    Joined:
    Sep 4, 2018
    Posts:
    5
    For anyone else who stumbles across this thread and tries all the solutions listed here, and if it still doesn't fix your problem...
    For me it was the Z position of my slider, it was too far on the negative Z. After zeroing it the slider worked, what was annoying was the fact that the slider still picked up on being pressed (as the slider handle changed colour when I pressed it) but wouldn't move. Just another possible fix for anyone...
     
  42. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    111
    Unity UI is a joke (tm).

    I got prefab (green arrow) with canvas group on it - of course it's interactable and blocking raycasts: everything on true
    It's the last object in the hierarchy.
    Button (red arrow) is interactable.
    There's a "Event System" component on the root object in the hierarchy, on the top of the hierarchy.
    There are no other UI elements that could possible block raycasts.

    And?

    F***ing button does not work! And off you go, making a game.... nothing mentioned above is working. I tried to delete / create Eventsystem multiple times, I tried to delete/create button again - NOTHING.

    Z values are at 0 on the button.

    Make a game w/ unity - go nuts! (tm)

    upload_2020-4-21_23-33-20.png
     
    chikandduck likes this.
  43. joasus12345

    joasus12345

    Joined:
    Dec 26, 2018
    Posts:
    11
    I had an image covering the whole canvas, it was supposed to be a fade out + text for the scene but it ended up blocking all the mouse clicks since it was drawn first i guess. I unchecked the raycast target on that image alone
    Found the issue after reading @vinay_vidhani 's answer, ty :p
     
  44. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    111
    @joasus12345 Not in my case - I got all UI components placed on their respective canvas groups, so I can easily control who's blocking raycasts and who's iteractable. I don't have "free-floating" images in the hierarchy.

    The way I workaround my issue above I moved button from the prefab and place it in scene hierarchy in the same level.
     
    joasus12345 likes this.
  45. jackyyang12345

    jackyyang12345

    Joined:
    Mar 24, 2020
    Posts:
    1
    I had all of the above, including all checked indicators with the eventsystem. I believe its a weird bug. If all the above failed, try creating a new scene, which will produce an eventsystem along with it. Copy and paste that eventsystem into your current scene. I checked and compared both eventsystems from my current and the new one. They had no differences on the ui, so it may be code/buggy related.
     
  46. jawaheryoucef

    jawaheryoucef

    Joined:
    Feb 7, 2020
    Posts:
    3
    i have a problem with unity 2019.3.1 somone help me!!!!!
    95833075_593953027996394_2353638182672662528_n.jpg 95655699_2785446098353960_5281605791667716096_n.jpg 95833075_593953027996394_2353638182672662528_n.jpg 95655699_2785446098353960_5281605791667716096_n.jpg
     
  47. jawaheryoucef

    jawaheryoucef

    Joined:
    Feb 7, 2020
    Posts:
    3
  48. Polarcube

    Polarcube

    Joined:
    Dec 7, 2019
    Posts:
    1
    I had this problem turns out I had accidentally deleted my event system.
     
    saxenasiddhant12 likes this.
  49. saxenasiddhant12

    saxenasiddhant12

    Joined:
    Dec 8, 2018
    Posts:
    1
    was exactly the same issue in mine lol Im dumb.. Thanks btw.
     
  50. bernardctxy

    bernardctxy

    Joined:
    Dec 22, 2019
    Posts:
    3
    Make sure there are no canvas component in the child except the parent
     
unityunity