Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Help Wanted UI Animation Problem

Discussion in 'UGUI & TextMesh Pro' started by leftshoe18, May 24, 2020.

  1. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    58
    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:

    Code (CSharp):
    1. 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.
     
  2. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    58
    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.
     
  3. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    809
    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.
     
    leftshoe18 likes this.
  4. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    58
    Yeah that was a typo on my fault copying it down here. Didn't realize the Select() thing existed. lol Thank you.
     
unityunity