Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[Solved] UI Button not working at all

Discussion in 'Unity UI & 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.
     
    fjyuan and aboazar like this.
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,137
    don't the raycasters go on the camera? not sure if that's an issue or you just need one in the scene...
     
  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.
     
  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)
     
  8. LeopardX

    LeopardX

    Joined:
    May 31, 2015
    Posts:
    61
    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.
     
  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 !
     
  15. dididucdich

    dididucdich

    Joined:
    Nov 29, 2016
    Posts:
    13
    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).
     
    RoninGT likes 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:
    5
    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
     
  19. meeruTheCoder

    meeruTheCoder

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

    anileapen05

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

    anileapen05

    Joined:
    Jun 8, 2013
    Posts:
    11
    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:
    2
    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.
     
  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
     
    wunder-ilmari likes this.
  24. Comafly

    Comafly

    Joined:
    May 30, 2014
    Posts:
    69
    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