When I assign a game object as the Event System’s currently-selected object it correctly selects the object but does not do the animation until I move off the object and come back to it. I’m simply setting the desired object through code using this:
EventSystem.current.SetSelectedObject(my button object);
Navigation through menus works just fine and like I said it actually does select the object (I can hit submit and use the menu option just fine without moving the selection or anything) it just doesn’t do the animation/transition correctly.
Well I found a solution that feels really hacky but it works. I added a coroutine that re-triggered the animation after waiting one frame. Since it’s in the menu only I’m kinda okay with this slight performance hit but I’m still confused as to why it’s happening in the first place.
I checked the source code. I couldn’t find SetSelectedObject()
but SetSelectedGameObject()
. That should actually trigger the state change with transition. Alternatively you could also write myButton.Select()
which does basically the same as the other line but does some additional checks (so, it is a bit safer to use that one, but on the other hand you don’t get informed if there is a problem).
It can be, if you try to set the selection right after loading the scene that the UI stuff is not fully initialized yet (the UI needs a frame for some stuff to layout correctly). In that case waiting one frame is the solution to go for. ´
This is not really a performance hit.
1 Like
Yeah that was a typo on my fault copying it down here. Didn’t realize the Select() thing existed. lol Thank you.