- Home /
First selected GameObject not highlighted
Hi! I'm having some issues concerning my pause menu. My pause menu consists of a Canvas with 3 Buttons (Resume, Exit to Main Menu, Exit Game). I want the buttons to be controllable by Gamepad. To begin with I just want the Menu to work fine with keyboard and later after I figured everything out I'll "convert" it to solo-gamepad-controls. In the Event System I dragged my Resume Button into "First Selected". This seemed to work. The problem is, that the button isn't highlighted. I know that the Resume Button is selected, because on pausing the game, the game continues after pressing Enter. I have to select the other buttons first (with the arrow keys up and down) to be able to highlight the different selected buttons. Does anyone know how to select AND highlight my first selected button?
Thanks in advance!
I have the same problem in the editor. I don't know if this happens playing the build. $$anonymous$$y menu starts disabled when I press play in the editor and it's enabled when I press "Escape". The first selected button on the Event System it's not highlighted. BUT if I press play in the editor with the $$anonymous$$enu enabled, all works fine and the first selected button is highlighted.
Answer by Isamaru · Jan 13, 2016 at 01:16 PM
I encountered the same issue, and this is probably due to the behaviour of the default Event System implementation when enabling some disable GUI GameObjects.
I found that deselecting and reselecting again via script works as a simple workaround (I do this in my LevelManager script):
// Deselect and reselect first button to correctly display highlight after enabling parent GO
EventSystem es = GameObject.Find("EventSystem").GetComponent<EventSystem>();
es.SetSelectedGameObject(null);
es.SetSelectedGameObject(es.firstSelectedGameObject);
Note that doing this plays the selection fade/animation again.
Answer by kamullis · Aug 09, 2016 at 04:24 PM
@MicDaRoc, not sure if you got this figured out, but I was having the same problem. I tried what @Isamaru suggested and it still wasn't working for me. Then I found this thread
about using coroutines. I'm still really a beginner, self-taught programmer and have never used these before. I'm not sure if I am really implementing it correctly, but I managed to make it work for me. So take this advice with a large grain of salt. Using what @Isamaru suggested above with the following
IEnumerator highlightBtn()
{
myEventSystem.SetSelectedGameObject(null);
yield return null;
myEventSystem.SetSelectedGameObject(myEventSystem.firstSelectedGameObject);
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.Escape) || Input.GetKeyDown(KeyCode.JoystickButton7))
{
isPaused = !isPaused;
StartCoroutine("highlightBtn");
}
...
Thank you! This is the work around that worked for me!!!
Answer by rajavamsidhar_gvs · Jul 21, 2015 at 11:41 AM
once you check this thread link it may help you..
Hmm, at first look this link doesn't help much. But thx. I think this may be a Unity Bug... Does anyone know a workaround for my problem?