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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Button click changes button color, but does not call OnClick handler

Discussion in 'Input System' started by wahntin, Nov 19, 2021.

  1. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    Hi,

    I'm facing a problem with the OnClick of buttons. I have a game component that represents a dialog and has an EventSystem with an InputSystemUIInputModule and a few buttons as children.

    When I click a button it properly changes color (selected and pressed), but the OnClick method is not called.

    The input system seems to be set-up correctly, at least the buttons change the color when I click them and this is definitely coming from the LeftClick of the InputSystemUIInputModule - I tested this by assigning another button in the InputActions.

    I can also manually call the OnPointerClick method of the button, which triggers my callback.

    I'm using input system version 1.1.1 in Unity 2020.3.20f1. I'm pretty sure that it worked with a previous unity + input system version, but I can't say when it stopped working, since the popup that is affected is only shown in error situations.

    I have no idea how to debug this any further, so any help is very welcome.
     
  2. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    I have used the samples from the input system package to rule out all possible problems one by one.

    It turned out, that the Click action I have bound to the EventSystem was of action type "Button". Changing this to action type "Pass Through" with control type "Button" works fine now.

    I'm not sure if this is an actual bug, but at it's at least not intuitive for me that this setting does not trigger the callback, but still leads to a visual click. I would have expected that it does either both or none.
     
  3. dante-signal31

    dante-signal31

    Joined:
    Apr 27, 2020
    Posts:
    2
    I've just had the same problem.

    My project was working a couple of months ago (2021.1.26f1) and today I continued with it but after upgrading the Unity version (2021.2.7f1), my UI buttons didn't triggered OnClick().

    After messing and trying everything, I googled and found your post. You are right, after changing the action type to "Pass Through" the thing worked again.

    I'm sure the Unity people changed something in the last few versions.
     
    wahntin likes this.