Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Help! Button not working

Discussion in 'UGUI & TextMesh Pro' started by Amegoro, Apr 8, 2023.

  1. Amegoro

    Amegoro

    Joined:
    Apr 1, 2023
    Posts:
    4
    Hello smart people,

    I've created a button with a sprite and the idea is to have it change sprite on hover and click. I'm using the Sprite Swap transition to do this.

    But when I hit play, nothing happens when I hover or click the button. I have an EventSystem, Interactable is checked on the button. I've also tried moving the button to the top and bottom of the panel, to see if something was in front of it.

    It's an FPS game using the Unity standard asset FPSController. Currently the game does not pause when the panel the button is in is active. Here is what things look like:




    (The button selected is the key icon shown on screen under Key Items in the game view)

    (More background info: Because my demo only has key items, I'm trying to get out of making a complicated inventory system by just having a fixed button/sprite appear in the inventory tab when the player has picked up one of the items, replacing an 'empty' sprite.)

    I've looked up and down for a solution and nothing has worked. If anyone knows what could be wrong I would be very grateful!


    Kindly,
    Josephine
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,553
    does your canvas have the physics raycast component?
    if you disable those other ui elements, does it work then?
    not sure why button has event system component?

    to debug,
    - press play
    - select event system
    - and check from bottom of inspector for the event system data (it shows what element is under mouse)
     
    Amegoro likes this.
  3. Amegoro

    Amegoro

    Joined:
    Apr 1, 2023
    Posts:
    4
    - No, the physics raycast was missing. I've added it now, the event mask is set to Nothing. No change yet though.
    - Disabling the other elements had no change also.
    - I've removed the event system component from the button.

    When clicking the event system in play mode, it did complain that I had the wrong Input System UI Input Module. I selected to switch to the right/new one.

    I'm not seeing the event system data though, the inspector just looks like this:



    I do suspect another thing though. When I am in play mode, I click the game screen and the cursor disappears. When I hit escape to see the cursor again, it is in the center of the screen. Could it be that the cursor jumps to the center of the screen automatically and stays there, so I can never actually move it onto the button and see if it works?
    I did try to move the button where the cursor appears, but there was no reaction.

    (Thank you! ^^)
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,553
    yeah it could be that cursor jump also.

    inspector bottom should have this panel that you can drag up,
    to see those details (whats under mouse and others)
    upload_2023-4-9_17-20-27.png
     
  5. Amegoro

    Amegoro

    Joined:
    Apr 1, 2023
    Posts:
    4
    Hmm okay, so it looks like a bunch of info is missing. It just says "EventSystem (UniEngine.InputSystem.UI.InputSystemUIInputModule)"

    When I hit escape to see the cursor and then click the button I get this:
     
  6. Amegoro

    Amegoro

    Joined:
    Apr 1, 2023
    Posts:
    4
    Update: As I try other UI methods, it's becoming clear that the standard asset FPS Controller is most likely the cause of me not being able to press any buttons.

    I will make my own Controller and see if that doesn't fix the problem. So I will consider this solved for now, if anyone reads this thread in the future.