Forum rules - please read before posting.

Force deselect of highlighted menu button?

I'm having a small GUI issue in my directly-controlled Unity UI menus. In the Pause menu you can press a button to go to the Start Game scene. When opening the Pause menu again after this, the last button is still highlighted along with the button I specified to be selected. It appears that the Pressed state (which turns the button alpha value to 0) is never triggered and the button stays in its highlighted form. This is probably a quirk in the Unity UI system or my implementation of it, but is there a way to disable all buttons before the Auto-select first visible element kicks in?

I've tried calling EventSystem.current.SetSelectedGameObject(null); in both an OnEnable and OnDisable function, but that didn't do the trick. In an Update function it works, but of course that just disables all buttons. Has anyone found a way to make sure buttons stay deselected after they've been pressed?


  • If you view the EventSystem's Inspector at runtime, it'll tell you what the currently-selected item is. Is it listing the old button?

    This may well be a Unity UI quirk, but try using AC's own SelectUIElement function, which should de-select the current object before the one specified:

    AC.KickStarter.playerMenus.SelectUIElement (myNewObject);
  • Thanks, the Rewired event system lists the auto-selected (correct) button as selected, so this is just a visual bug - the highlighted button fortunately does not activate unless re-selected. I'll see if I can find a way to force all buttons to become set to their normal state visually when the menu is enabled. If setting the button's Navigation to none this bug disappears, but that of course makes it impossible to direct-control. I'll dig around and report back here if I find a solution.

  • For posterity, I never was able to fix this gracefully. I ended up making an actionlist that runs on a button press that selects the first available menu item, waits 0.1 seconds, then closes the menu and continues. Forcing the first selected item and waiting stopped Unity from keeping the last selected button visible. This 6 year old thread on the Unity forums shows that people are still having problems with this (none of the fixes here worked for me):

  • So this is a behaviour issue with Unity UI?

    It may be worth looking into a custom StandaloneInputModule subclass, but it's a bit of a rabbit hole..

  • Yes, I believe this is a side effect of Unity UI buttons with automatic navigation, but good that a simple actionlist avoided the issue 😀
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.