Search Unity

[Solved] UI Button not working at all

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

  1. Mamta_kh

    Mamta_kh

    Joined:
    Nov 1, 2019
    Posts:
    2
    I solve it, Actually some transparent panel was blocking it.
     
    yosefbesher34 likes this.
  2. Freddy03060

    Freddy03060

    Joined:
    May 1, 2020
    Posts:
    2
    If you have created something like a pause menu then make all over canvases disabled whilst within the Pause Menu using (Canvas Name).SetActive(false); Make sure to Reference the canvas as a game object if your new to unity :)
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    I solved mine by deleting all canvas in parents of the button. Why did the canvas block raycast in the first place? I have no idea.
    I was using canvas to group batches and with them gone now nothing batches according to the frame debugger.
     
  4. AlterContacts

    AlterContacts

    Joined:
    May 18, 2020
    Posts:
    1
    Definitely a bug. I have done A/B testing and makes no sense whatsoever
     
  5. perkays

    perkays

    Joined:
    Jul 10, 2020
    Posts:
    2
    canvas > set order > 1
     
  6. ColtPtrHun

    ColtPtrHun

    Joined:
    Nov 20, 2019
    Posts:
    9
    Hi everyone!

    I had the same problem, and for me the solution was to look for the EventSystem in the hierarchy. There is a Standalone Input Module which I disabled because it always creates additional inputs in the input manager which is quite annoying. However as soon as I reenabled it, the buttons worked...

    -Peter
     
    lucbloom, NpcBoss and Mario-M701 like this.
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    This might be the most accurate solution. Show us your hierarchy.
     
  8. codemaker2015

    codemaker2015

    Joined:
    Aug 19, 2018
    Posts:
    27
    Don't forget to add EventSystem in your scene. If the scene doesn't have any event trigger is not able to track any events that's happening in the scene
     
  9. codemaker2015

    codemaker2015

    Joined:
    Aug 19, 2018
    Posts:
    27
    Ensure that the scene contains EventSystem
     
  10. Commendev

    Commendev

    Joined:
    Oct 1, 2020
    Posts:
    2
    oh yes i deleted it thinking that it not needed to me i feeling self as idiot
     
  11. Ar3max

    Ar3max

    Joined:
    Aug 6, 2019
    Posts:
    1
    Before Changing Any Settings or adding Anything, DO THE FOLLOWING:-
    1. Create an Empty Project.
    2. Right Click in Hierarchy and from UI, select Button.
    3. Play The Scene and Check if the Button is working or not.


    Point1:- If the Button is Working, that means you have done something wrong in your Project(where it's not working).
    In that case, follow the solutions provided by others. One of them might surely work.

    Point 2:- If the Button is not working, then that means Your Unity Editor has some bugs or You did something (unknowingly) which caused the UI's not work.

    Solution: If your case is Point 2, then I guess nobody know how to fix it, or if Someone knows, then he didn't shared it.
    The Only thing You can do is Upgrade Your Unity Version.

    The Problem Happened to my Unity 2020.1.4f1. I tried all the solutions(from different forums), but nothing worked.
    Then I decided to change the Unity Version to see if works or not.
    I opened UnityHub>Installs>Add, there I was about to install the Recommended Released LTS version, but then I saw there is a Pre-released Alpha Version Unity 2021.
    I installed it(cause I wanted to) and when I opened that same Project in this alpha version. The Problem is just gone.

    * Since I got the solution in my first attempt, I didn't bother to install any other version. But I am pretty much sure changing to any other version will work.
    * Remember I installed another version from UnityHub, not from Unity Edtor>Help>Check for Updates.
     
  12. trakevital

    trakevital

    Joined:
    Sep 25, 2020
    Posts:
    2
    Damn Right! I forgot to ADD the event system
     
  13. brodiealmy5

    brodiealmy5

    Joined:
    Feb 27, 2020
    Posts:
    2
    BRUH ME TOO
     
  14. mikargibbros

    mikargibbros

    Joined:
    Nov 30, 2020
    Posts:
    1
    My button needed to be inside a canvas with a "Graphic Raycaster" component.
    My button needed to have "Raycast Target" checked.
     
  15. fahrimuham001

    fahrimuham001

    Joined:
    Oct 13, 2020
    Posts:
    1
    In my case I fix it by just adding event system that I coincidently deleted it
     
  16. JulianSyno

    JulianSyno

    Joined:
    Dec 9, 2020
    Posts:
    1
    My Buttons are working on the canvas, but as soon as I enable a player controller script (attached to a player with camera) they stop working and don't even change color when you mousehover them. I am very new in unity and couldn't find the error :(

    I'm doing this for a university project and would be very thankful for any help.

    This is the code from the player controller script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     [SerializeField] Transform playerCamera = null;
    8.     [SerializeField] float mouseSensitivity = 3.5f;
    9.     [SerializeField] float walkSpeed = 6.0f;
    10.     [SerializeField] float gravity = -13.0f;
    11.     [SerializeField] [Range(0.0f, 0.5f)] float moveSmoothTime = 0.3f;
    12.     [SerializeField] [Range(0.0f, 0.5f)] float mouseSmoothTime = 0.03f;
    13.  
    14.     [SerializeField] bool lockCursor = true;
    15.  
    16.     float cameraPitch = 0.0f;
    17.     float velocityY = 0.0f;
    18.     CharacterController controller = null;
    19.  
    20.     Vector2 currentDir = Vector2.zero;
    21.     Vector2 currentDirVelocity = Vector2.zero;
    22.  
    23.     Vector2 currentMouseDelta = Vector2.zero;
    24.     Vector2 currentMouseDeltaVelocity = Vector2.zero;
    25.  
    26.     void Start()
    27.     {
    28.         controller = GetComponent<CharacterController>();
    29.         if (lockCursor)
    30.         {
    31.             Cursor.lockState = CursorLockMode.Locked;
    32.             Cursor.visible = false;
    33.         }
    34.     }
    35.  
    36.     void Update()
    37.     {
    38.         UpdateMouseLook();
    39.         UpdateMovement();
    40.     }
    41.  
    42.     void UpdateMouseLook()
    43.     {
    44.         Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
    45.  
    46.         currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
    47.  
    48.         cameraPitch -= currentMouseDelta.y * mouseSensitivity;
    49.         cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f);
    50.  
    51.         playerCamera.localEulerAngles = Vector3.right * cameraPitch;
    52.         transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity);
    53.     }
    54.  
    55.     void UpdateMovement()
    56.     {
    57.         Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    58.         targetDir.Normalize();
    59.  
    60.         currentDir = Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity, moveSmoothTime);
    61.  
    62.         if (controller.isGrounded)
    63.             velocityY = 0.0f;
    64.  
    65.         velocityY += gravity * Time.deltaTime;
    66.  
    67.         Vector3 velocity = (transform.forward * currentDir.y + transform.right * currentDir.x) * walkSpeed + Vector3.up * velocityY;
    68.  
    69.         controller.Move(velocity * Time.deltaTime);
    70.  
    71.     }
    72. }
     
  17. WizardGameDev

    WizardGameDev

    Joined:
    Jul 25, 2012
    Posts:
    62
    There are so many things I love about Unity... but one of the most steep curves they put in front of people should be one of the most simple things possible to troubleshoot. I have a ton of courses i've put on Udemy and my own private courses, I've consulted on over 200 games and this is in my top 3 pain in the neck troubleshooting areas. Too many poorly integrated and documented systems that do nothing to provide the level of feedback a developer would need to troubleshoot what is going on. They need an intelligent camera/view/layer manager that can look at what is trying to be done and setup configurations that work out of the box. Let the computer go down a checklist of 8-10 settings to determine why you can't click a button or see your sprite. Crazy town. End rant.
     
  18. deplorablemountaineer

    deplorablemountaineer

    Joined:
    Jun 16, 2018
    Posts:
    12
    Ok--I have found yet one more possible cause:

    As with others, the button didn't work---it would visually depress, but nothing would happen.

    It turned out, I was having the button call a method on a persistent singleton object, one that was loaded in another scene and placed under "Do Not Destroy On Load". The object the button was calling from wasn't the same object that existed, as a result, but a copy that had been destroyed by the singleton on scene load.

    The solution was to make a new script, attach it to the button itself, one that is neither persistent nor a singleton, and I called the method from that script instead. Very frustrating problem solved!
     
  19. rukaiyasneha118

    rukaiyasneha118

    Joined:
    Dec 29, 2020
    Posts:
    1
    wow I solved the problem by Disabling it but THANKS
     
  20. yosefbesher34

    yosefbesher34

    Joined:
    Dec 29, 2020
    Posts:
    3
    Same
     
  21. yosefbesher34

    yosefbesher34

    Joined:
    Dec 29, 2020
    Posts:
    3
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MouseLook : MonoBehaviour
    6. {
    7.  
    8.  
    9.    
    10.     public float lookspeed = 100f;
    11.     public Transform playermo;
    12.     float rtr = 0f;
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         Cursor.lockState = CursorLockMode.Locked;
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.         float mouseX = Input.GetAxis("Mouse X") * lookspeed * Time.deltaTime;
    23.         float mouseY = Input.GetAxis("Mouse Y") * lookspeed * Time.deltaTime;
    24.  
    25.         rtr -= mouseY;
    26.         rtr = Mathf.Clamp(rtr, -90, 90);
    27.         transform.localRotation = Quaternion.Euler(rtr, 0f, 0f);
    28.  
    29.         playermo.Rotate(Vector3.up * mouseX);
    30.     }
    31. }
    32.  
    When I enable the script I cant click the button why?
     
  22. screret

    screret

    Joined:
    Apr 25, 2020
    Posts:
    5
    That's because in the editor if you press escape it actually forces the cursor to free, bu the game still think's that's what has happened.
    So the cursor.locstate=lockmode.locked is what's causing that.
    Create a script that frees the cursor to cursorlockmode.none when paused and lock it again when unpaused.
     
  23. Kewlife

    Kewlife

    Joined:
    Apr 12, 2016
    Posts:
    6
    If you have or make during any coding any Ui it is best to make sure your colliders, shown as a box moving w each UI , is stacked, best to make sure they all are the same but definitely needs the parent panel and each item or yu get the touch wherever that ui collider is
     
  24. zacharyaghaizu

    zacharyaghaizu

    Joined:
    Aug 14, 2020
    Posts:
    65
    My Issue Was solved by Removing empty functions GameObjects in the Onclick. This issue Might have started when I deleted and duplicated them at runtime to replace them.
     
  25. Baldor

    Baldor

    Joined:
    Jul 24, 2018
    Posts:
    5
    My Issue Was solved by checking "interactable" in the canvas group of the parent gameobject and the button itself.
     
  26. bruceweir1

    bruceweir1

    Joined:
    Nov 29, 2017
    Posts:
    15
    Updated for the new Input System.

    Under Player Settings..... Input System Package, check that the Default Button Press Point has not been set to 0.
    This prevented buttons in Android raising an onClick event. Setting the value to 0.5 worked fine.
     
  27. YPCuber

    YPCuber

    Joined:
    Jan 21, 2021
    Posts:
    1
    Thank You sooooo much for this. I would have gone mad if i didn't find this comment so thank you
     
  28. unity_bRON2GqN9cCGyg

    unity_bRON2GqN9cCGyg

    Joined:
    Mar 2, 2021
    Posts:
    1
    my buttons were not working too. It is working now because there is no event system. Thank you very much.:)
     
  29. turtle_fish

    turtle_fish

    Joined:
    Sep 10, 2018
    Posts:
    1
    my g
     
  30. Benoprogramok

    Benoprogramok

    Joined:
    Apr 15, 2021
    Posts:
    2
    Same... :(((((((((((((((((((((((((((((((((((
     
  31. westmat002

    westmat002

    Joined:
    Mar 30, 2021
    Posts:
    1
    Sometimes if you parent a button to something inside the canvas and not directly to the canvas it causes the button to not work.
     
  32. Stiip

    Stiip

    Joined:
    Nov 17, 2020
    Posts:
    1
    ahahah me too!
     
  33. pedroarruda4991

    pedroarruda4991

    Joined:
    Jan 9, 2021
    Posts:
    20
    Same 2
     
  34. pedroarruda4991

    pedroarruda4991

    Joined:
    Jan 9, 2021
    Posts:
    20
    Hey guys, after days trying to solve this problem, a friend help me with that!

    If you are using a type of first person controller asset and nothing was solved, you have to check the camera movement script on this asset.

    In my case, the asset mini first person controller was disabling the cursor when the player returns to the main menu scene. So if you have this problem, you have to change the asset script, and menu will work.
     
    LightID likes this.
  35. siddhantbansod07

    siddhantbansod07

    Joined:
    Oct 15, 2020
    Posts:
    1
    omg ilysm ik this is an old thread but oh my god you just saved me from dying
     
  36. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    THIS!!!!
    It took me hours to figure this out.
    Thank you.
     
  37. Henrys-Studio

    Henrys-Studio

    Joined:
    Jul 6, 2021
    Posts:
    1
    I found out just now that TMP messes with the shader channels and that broke my UI, I got it fixed now.
     
  38. tumeechugames

    tumeechugames

    Joined:
    Apr 21, 2021
    Posts:
    1
    I tried everything more than half an hour and seemed that nothing was working for me.
    The issue was that by using the new input system i didn't put a mouse in the Project Settings -> Input System Package -> Supported Devices.
     
  39. Snickerade

    Snickerade

    Joined:
    Apr 4, 2021
    Posts:
    1
    Another Point. If your cursor is set to CursorLockMode.Locked while clicking, it wont trigger OnClick() for buttons
     
  40. MosaabMatar

    MosaabMatar

    Joined:
    Jul 3, 2021
    Posts:
    1
    My Problem is my Main Menu were you start the game is working and when you press start in the main menu it took you to the first level which have a pause menu and no buttons sliders or dropdowns ... are working
     
  41. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    20
    I have also tried every suggestion in this thread, but none worked.

    After some sick trials, I found out that,
    • if I create the button right clicking the children of the main canvas like layout groupers etc., the button didn't work.
    • if I add button component to the children, the button didn't work,
    • if I create the button right clicking the main canvas, than the button work flawless.
    Seems to be weird but it solved my problem, hope it helps anyone else...
     
  42. MindGem

    MindGem

    Joined:
    May 11, 2017
    Posts:
    84
    Many people looking up this thread should check if they deleted their EventSystem. If that is gone the buttons wont work, I have no idea why but this was the problem for me. and as a newbie I bet others do the same mistake.
     
  43. juliangubbels06

    juliangubbels06

    Joined:
    Sep 14, 2020
    Posts:
    2
    After 3 hours of searching the solution for me was to just delete the EventSystem and created a new one.
     
  44. Kareem_Hossam

    Kareem_Hossam

    Joined:
    Sep 9, 2021
    Posts:
    3
    Thank you so much you saved my project i have been deppressed for 2 days thank you one more time
     
  45. madara5555

    madara5555

    Joined:
    May 4, 2021
    Posts:
    8
  46. poderosisimo_lider_aguila

    poderosisimo_lider_aguila

    Joined:
    Mar 30, 2021
    Posts:
    1
    omg you saved me!!, thank you soooo much <3, i almost fall into depression.
     
  47. panderson9149

    panderson9149

    Joined:
    Nov 26, 2020
    Posts:
    6
    I had a similar issue. My problem was that I created an empty object to help organize some game objects. Then I added a canvas component to the empty object to control "Sort Order" for the group. But buttons under that object stopped accepting inputs. I added a Ray Caster to the empty object and now it all works.
     
  48. azizkale

    azizkale

    Joined:
    May 18, 2019
    Posts:
    5
    I had the same problem. I have TextMeshProUGUI in my hierarchy. First I set the font size instead of TextMeshPro's scaling. But it prevented the button's event and because the background was transparent ı couldn't notice it.
    After that, I made smaller the scale of the TextMeshPro and made bigger font size. And problem was gone.
    And adding the camera to the canvas can solve it as well.
     
    Last edited: Nov 24, 2021
  49. unity_ECC010AD1DAD4A8AC482

    unity_ECC010AD1DAD4A8AC482

    Joined:
    Sep 25, 2021
    Posts:
    1
    I have this problem. And although I followed all the steps it ain't working.
    Can't find any solution I am confused.
     
  50. Thunderbolt895

    Thunderbolt895

    Joined:
    Oct 17, 2021
    Posts:
    1
    I have tried every possible comment in this page and my button still doesn't work . Please if anyone can find the solution . I am making a game which has levels . In it I have the first level which work completely fine and there is the second level which doesn't work and it has the exact same button / UI . For the first level I made the buttons fresh and made them into prefabs . In the second level I used the prefab which doesn't work now
     
    Last edited: Dec 19, 2021