Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[Solved] UI Button not working at all

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

  1. vejab

    vejab

    Joined:
    Dec 21, 2021
    Posts:
    74
    The panel on which the buttons were placed had a Canvas component. Removing this component solved the issue for me.
     
  2. Juan_Manuel_Rider_Jurado

    Juan_Manuel_Rider_Jurado

    Joined:
    Nov 19, 2021
    Posts:
    2
    I had this same problem although it was none of the above, in my case I deleted by mistake the EventSistem GameObject, I'm working in the 2020.3.14f1 version and if you don't have an EventSistem GameObject, one is automaticaly created when you create a canvas
     
  3. Juan_Manuel_Rider_Jurado

    Juan_Manuel_Rider_Jurado

    Joined:
    Nov 19, 2021
    Posts:
    2
    I was in your exact position and I solved it, I'm the #102 comment
     
  4. Wesleywalstonxx

    Wesleywalstonxx

    Joined:
    Nov 8, 2021
    Posts:
    1
    I Had a problem when I switched scenes and I couldn't use my UI buttons anymore, but I was brainstorming and I had an idea on how to fix it and it worked it was so unbelievably simple. Use a cursor lock state and a Cursor lock mode Confined, and for the people who don't know what I'm talking about heres the code. Lost File - Microsoft Visual Studio 1_10_2022 11_56_04 PM.png
     
  5. milantelt

    milantelt

    Joined:
    Jul 1, 2021
    Posts:
    1
    I removed my EventSystem so stupid, adding it back helped me.
     
  6. nathan2019spence

    nathan2019spence

    Joined:
    Jan 21, 2022
    Posts:
    11
    Be careful, if you use the the prefab third person controller it contains its own event system, and will make your buttons stop working. grrr
     
  7. unity_w36k9MNcB9_bxg

    unity_w36k9MNcB9_bxg

    Joined:
    Jan 23, 2022
    Posts:
    1
    Resolveu meu problema! Obrigado.
     
  8. pythontest456

    pythontest456

    Joined:
    Jan 29, 2022
    Posts:
    1
    for me it was loading a scene through script
    this line specific: SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    hope this would save some time to a few
     
  9. LightID

    LightID

    Joined:
    Mar 11, 2021
    Posts:
    3
    Thank you!!!! The problem is that if you lock your cursor, 'There are no guarantees of where a locked cursor should be on the screen. Thus we(the devs) have removed the interactability of a locked cursor with the UI.'
     
    Last edited: Mar 16, 2022
    Lekteroi and pedroarruda4991 like this.
  10. leanhquang2803

    leanhquang2803

    Joined:
    Dec 18, 2021
    Posts:
    2
    I had the same issue. This is my solution:
    1. Go to the parent game object of the button.
    2. Reorder the button to the lowest position of the parent game object.
    3. Test out your button again.
    Why? Some other UI components or game objects might be above your button and won't allow you to click the button.
     
  11. kevinkevin1

    kevinkevin1

    Joined:
    Mar 3, 2022
    Posts:
    1
    I was able to fix mine by moving the event system outside of the canvas. I have to canvas and one of them contains the event system, but I am enabling and disabling that canvas for certain reasons. Adding multiple eventsystem inside canvases would also work but an alert message would pop up. One event system is enough, just ensure that it can be accessible by all UI components
     
  12. ninagbr

    ninagbr

    Joined:
    Apr 4, 2022
    Posts:
    1
    If it is something you changed within your project, my solution was
    to deactivate all components on the scene and enabling them one by one.
    I checked to see when button works and when not, and I found that the problem was with one particular object which had an "override layer" (sth sth dont remember) on the Tab/Layer/Module tab on the inspector (the one on the very top). I reset the settings there and the problem was solved.
     
  13. johntitortheprogrammer

    johntitortheprogrammer

    Joined:
    Jul 26, 2021
    Posts:
    1
    guys i realized my problem. if you bind a camera to any canvas and if you close it in the game later you should do overlay mode to canvas
     
  14. Max_dragotoba

    Max_dragotoba

    Joined:
    Nov 16, 2021
    Posts:
    1
    make sure that the parent and the button itself have a scale of 1. having the scale at 0 was my problem.
     
  15. NpcBoss

    NpcBoss

    Joined:
    Dec 9, 2021
    Posts:
    3
    Its the Event System hahahah, i used it before but forgot to add at the next scene, how stupid lol
     
  16. Japppe

    Japppe

    Joined:
    Sep 9, 2013
    Posts:
    1
    Thanks alot, worked like a charm after adding it back!

    Just create an new empty game object -> Add component "Event System"
     
  17. Arsenyokh

    Arsenyokh

    Joined:
    Aug 23, 2022
    Posts:
    1
    If you had this problem, baybe you delete EventSystem. You can add it Hierarchy>> right mouse button>> UI>> EventSystem
     
  18. hammerboard

    hammerboard

    Joined:
    Dec 21, 2020
    Posts:
    1
    Thx to this hint which led me found that my Event System Game Object was missing. Once I created in the main scene buttons work.
     
    ayhaab-pasha likes this.
  19. ABalniko

    ABalniko

    Joined:
    Apr 16, 2022
    Posts:
    1
    My problem was I put canvas for the inventory, etc.. under the canvas, not panels. As soon as I replaced them with a panel, my problem was solved.
     
  20. nudz-klecany

    nudz-klecany

    Joined:
    Oct 6, 2015
    Posts:
    3
    OK, so I encountered a very strange behavior. Following NO CHANGES in the scene containing the UI one particular UI button simply stopped working. After reverting all (absolutely unrelated) changes via source control, the UI button still not working, even if the scene is EXACTLY the same as before when it was clearly working. Hopeless found this thread and tried deleting and recreating the event system (which BTW looks exactly the same as it did before), voila button suddenly working!!! So happily redid all the changes that I previously reverted due to an unsuccessful attempt to fix the UI and guess what - the very same button NOT WORKING AGAIN!!! So if you ever want to recreate this bug simply create two Inspector windows while in the prefab variant edit mode, lock one of them and watch your UI break for no apparent reason. For me happened in Unity 2019.4 but not sure if it does not happen in other editor versions as well...
     
  21. VicktorOti

    VicktorOti

    Joined:
    Oct 1, 2020
    Posts:
    5
    I had a similar issue. Creating an empty GameObject inside the Canvas element and nesting sliders, toggles, etc. within it caused problems.

    Removing the UI input elements and making them direct children of the Canvas GameObject fixed everything.
     
  22. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    123
    This is killing me.

    I have a script that is supposed to allow a non-VR user to click on Objects on a PC monitor while another user is in VR. The PC user clicking the objects triggers events and the script has been working for weeks but suddenly stopped.
    I have checked my physics settings and matrix.
    The Object has a rigid body and collider that becomes active on hover,
    The layer and tags are set.
    No other colliders blocking the RaycastHit.
    The camera has a Physics Raycaster Max Ray Intersection 0. Event Mask is set to everything.
    There are no errors but I don't even get debug logs when clicking on the objects.

    Here is the script which was working and works in a backup scene on another machine but after adding new interactions it suddenly stopped working:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3.  
    4. public class MouseClickDoX : MonoBehaviour
    5. {
    6.  
    7.    public UnityEvent mouseClickEvent;
    8.    private GameObject button;
    9.  
    10.    private void Start()
    11.    {
    12.        button = this.gameObject;
    13.    }
    14.  
    15.    private void Update()
    16.    {
    17.  
    18.        if (Input.GetMouseButtonDown(0))
    19.        {
    20.            RaycastHit hit;
    21.            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    22.  
    23.            if (Physics.Raycast(ray, out hit, 1000.0f) && hit.collider.gameObject == button)
    24.            {
    25.                Debug.Log("Hit collider: " + hit.collider + ", target: " + button);
    26.                Debug.Log("hit.collider == target" + hit.collider + button);
    27.                if (hit.transform != null)
    28.                    //mouseClickEvent.Invoke();
    29.                    CurrentClickedGameObject(hit.transform.gameObject);
    30.            }
    31.        }
    32.    }
    33.  
    34.    public void CurrentClickedGameObject(GameObject gameObject)
    35.    {
    36.        if (gameObject.tag.Contains("button"))
    37.        {
    38.            mouseClickEvent.Invoke();
    39.        }
    40.    }
    41. }
    I have a canvas with UI buttons that I can click and activate the interactable objects but those objects are no longer registering a raycast. Hovering the objects has an effect but clicking them does not.


    I have tried everything in this thread.
    There seems to be a strange bug in Unity where copying and pasting a button can break things in the event system. It seems some users were able to fix this by deleting and recreating the Event system or changing toggles in the event system however non of that worked for me. Luckily I had a backup from minutes before the issue started. I went back to that backup on the same machine and the issue persisted. I had the backup on a flash drive and tested it on another machine and it worked fine. I was able to move that flash file back to the primary machine and it works again in both files so somehow I tricked the bug into working again. After about 4 hours of playtesting no issues and no changes to code or any objects in the scene the bug suddenly returned after closing and reopening Unity.
    I'm in Unity 2020.3.29 and could really use some ideas on how to fix this.
    Thanks.

    P.S. It still works on my laptop it just glitches and stops working on my desktop. Is there a cache file holding some corrupted unity setting that I could delete or something?

    EDIT:
    I tried using iPointerHandler script instead of raycast hit but it didn't work either.
    I ended up having issues with monobehavior not reading and in my code editor and even though the pugging where active and what not. I had to uninstall Unity and all versions then reinstall delete .csproj/.sln files and library folder and things still dent work.

    I finally got the iPointerClick Handler to work by adding a blank OnPointerUp() and OnPointerDown() which is not mentioned as needed in the Unity docks but once I added them things finally worked.?!
     
    Last edited: Oct 24, 2022
  23. DovyBL

    DovyBL

    Joined:
    Mar 27, 2022
    Posts:
    2
    I have read all comments from the first page(#50)
    Nothing. Tried everything exept redoing everything, which would take me about 2h and will probably bug again when I restart Unity.

    It worked perfectly. I closed unity and went to sleep. Next day I launch unity and it doesn't work at all. Then I tried everything above. still nothing.

    There are no unnecessary components, or GameObjects; There is only one canvas and only one Event system at the top of the hierarchy, both with correct components and values (Even tried different combos); Everything is z = 0, canvas is 10 (tried 100 and 1000 to).

    Attached my hierarchy
    I have buttons only on the PauseMenu (panel) object - I enable it via script when escape is pressed
     

    Attached Files:

  24. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    123
    What's your script look like? Are you using the new input system the old or both? Are you ray casting UI buttons, game Objects or both? It seems that if all of the steps from previous posts have been done and if its not a case of a bad Event system or where iPointerHandler script should be used instead of raycast then this issue may need a ticket filed as it sometimes works until Unity reboot and then fails without explanation.
     
  25. Kadudu3K

    Kadudu3K

    Joined:
    Dec 9, 2022
    Posts:
    1
    The button's text should have its ray cast checkbox (text mesh pro, extra settings) turned off so it stops blocking it. Also have event system thingy.
     
  26. vBayKer

    vBayKer

    Joined:
    Oct 13, 2019
    Posts:
    1
    I had this problem, but I realised it was because I accidentally deleted my "EventSystem" that comes when you add the Canvas.
     
  27. kowcp91

    kowcp91

    Joined:
    Sep 15, 2022
    Posts:
    1
    Hi everyone,
    In my case it is Starter Asset player controller to blame. Once I disabled whole imported player placeholder the buttons are working fine. Still looking for solution. If I find any I'll let you know.