Search Unity

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

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice

(EventSystem) SetSelectedGameObject is causing my button to fire an onClick Event?

Discussion in 'UI Toolkit' started by tomph, Sep 29, 2021.

  1. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    HELP! :)

    I've been going around in circles for the last day. I'm trying to enable/disable controller UI navigation within a scene.

    I figured the easiest way would be to do the following to disable:

    Code (CSharp):
    1. EventSystem.current.SetSelectedGameObject(null);
    2. EventSystem.current.sendNavigationEvents = false;

    and the following to enable:
    Code (CSharp):
    1. EventSystem.current.SetSelectedGameObject(firstButton);
    2. EventSystem.current.sendNavigationEvents = true;
    My issue is that when I enable it, the SetSelectedGameObject call is hitting my onClick event within that gameObject? Not sure why this would be happening.

    Weirdly if I don't use the controller at all (mouse) before I enable navigation, it works as expected - button is selected but NOT clicked. If I use the controller, the click is registered as soon as I re-enable navigation. What could the controller be doing that is causing this?

    Any help would be amazing, thanks!
     
  2. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Fixed it.... For anyone finding this error, upgrade new Input System package to 1.1.1 and the issue will magically go away!
     
unityunity