Search Unity

Button onClick() not working but others Buttons are working fine

Discussion in 'Editor & General Support' started by JoaoBM, Jan 9, 2019.

  1. JoaoBM

    JoaoBM

    Joined:
    Sep 23, 2018
    Posts:
    11
    Hey there!

    Im hours away from delivering my Project and of course something had to happen to prevent me from progressing.

    I have a Menu that shows up if the player loses and calls 2 functions. One to load the Main Menu and another one to save data.

    Upon clicking, the button takes me to the Main Menu but it is not saving the data. Even with a Debug.Log() on top of that function, nothing is being printed on the console.

    I have already tried to rebuild the button, copy from another existing button that does almost the same thing, delete the canvas and EventSystem and add them again.

    Any help would be greatly appreciated.

    Edit:

    Here's a screenshot of the button: https://imgur.com/a/LKFd4QM

    As you can see, the Button has a Load Scene that works just fine and another function that doesn't print anything in the console:

    Code (CSharp):
    1. public void DebugTest() {
    2. Debug.Log("test");
    3. }
     
    Last edited: Jan 11, 2019
  2. Gambit-MSplitz

    Gambit-MSplitz

    Joined:
    May 16, 2015
    Posts:
    1,104
    Make sure other UI that overlap the button have "Raycast Target" set to false. On the GraphicRaycaster attached to your canvas, set the Blocking Mask to "Nothing" so that non-UI can't block input to your UI.
     
  3. JoaoBM

    JoaoBM

    Joined:
    Sep 23, 2018
    Posts:
    11
    The thing is, I have 2 functions in this button. One runs but the other doesnt. Not even a simple Debug.Log message is shown

    I have updated the post with a screenshot.
     
    Last edited: Jan 11, 2019
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,678
    I'm not sure, but I personally have never seen two scripts called for a single button. Although your screenshot seems to imply that it should work. Why not call the second method from the first?
     
  5. JoaoBM

    JoaoBM

    Joined:
    Sep 23, 2018
    Posts:
    11
    At first it was because of organization since both have different tasks and are located in different scripts. I did think about that option, although I can afirm that it was working with both scripts before it bugged. I will give it a show and will update accordingly.
    I do think this issue came from Unity Collab. Both my partner and I spent the whole day sending back and forward tons of updates and it might have somehow bugged the button.

    Thank you for your reply.

    Edit: Ill just rebuild my project from the ground. Easier since I already have the scripts and objects.
     
    Last edited: Jan 12, 2019