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

HELP! :slight_smile:

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:

EventSystem.current.SetSelectedGameObject(null);
EventSystem.current.sendNavigationEvents = false;

and the following to enable:

EventSystem.current.SetSelectedGameObject(firstButton);
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!

Fixed it… For anyone finding this error, upgrade new Input System package to 1.1.1 and the issue will magically go away!

I am having this issue in Input System 1.4.0!

It is driving me up the wall. I can’t figure out what is triggering my buttons but it happens as soon as SetSelectedGameObject is called.

Please tell me this is not just an unsolvable but with Input System :frowning:

This problem still exists in Input System 1.4.4… did anybody find a solution for this?
My workaound is to register callbacks in coroutines with very short delay after I set the selected Gameobject.

Yeah I’m in version 1.3.0 (the newer ones don’t appear in the package manager in unity 2021.3.4f1 for some reason, but I need wsad player movement so I’m not going to bother upgrading until that’s fixed), the issue is in this version also and is incredibly frustrating.

Did anyone find a work around or fix that doesn’t involve coroutines or changing all button input to release instead of press? I have my code all nicely set up and I don’t want to make it convoluted by passing every single player input through a coroutine just to check if it’s really meant to be triggering any actions. Is there maybe a way to reset the input so it’s not being registered as performed when it really shouldn’t be?

I am on 1.6.3 (bug still present) and this seems to have solved the issue:

//where eventer is EventSystem and target is GameObject
eventer.sendNavigationEvents = false;
eventer.SetSelectedGameObject(target);
eventer.sendNavigationEvents = true;

My previous post only works with mouse, this works for MultiplayerEventSystem with Mouse&Keyboard or Gamepad:

void Focus(EventSystem eventSystem, GameObject goj)
{
    eventSystem.enabled = false;
    eventSystem.sendNavigationEvents = false;
    eventSystem.SetSelectedGameObject(null);
    eventSystem.SetSelectedGameObject(goj);
    eventSystem.sendNavigationEvents = true;
    eventSystem.enabled = true;
}

This works - thank you - but WHY?! Why should anyone need a workaround like this?!

1 Like

Still busted for me on 1.7, even with that workaround :frowning: