0
\$\begingroup\$

I have a main menu scene in which the buttons work using button component's animation transition. I created a simple animation for them that changes their vertex color to blue when selected. The problem is that surprisingly, some of them don't work this way. In fact, they don't even work with other transitions such as color tint.

As you can see in the gif, the animation transitions are working fine. But the truth is that these are (plus a few other buttons in the options menu) the only buttons that have working transitions.

enter image description here

When you press the quit button, a small panel shows up that asks if you really want to quit the game. This is where the problem appears. Although the yes button should be selected based on the script, it just stays unselected which also shows that the transition animation is not working. I've checked these buttons using animation tab's preview mode and they seem to work fine there but when the actual game starts, they just remain unselected.

enter image description here

I realized that there should be a big structural difference between the buttons that work and those that don't but I'm not able to find it. To prove this, I changed the transition mode of new game button (that is working fine) and the highlighted and selected color turned blue but when I did the same for the yes button (which cannot be selected), there was no change in the colors.

enter image description here

enter image description here

This is the part in my main menu script that controls the exit panel. I don't see any problems in the script as I don't in the editor. But still, some of the buttons can't be selected when the condition is due (All the game objects are assigned in the inspector).

   public void OpenExitPanel()
    {
        exitPanel.SetActive(true);
        EventSystem.current.SetSelectedGameObject(null);
        EventSystem.current.SetSelectedGameObject(exitPanelFirstButton);
        mainMenu.SetActive(false);
    }

    public void CloseExitPanel()
    {
        exitPanel.SetActive(false);
        EventSystem.current.SetSelectedGameObject(null);
        EventSystem.current.SetSelectedGameObject(exitPanelClosedButton);
        mainMenu.SetActive(true);
    }

I also tried creating new buttons (Text Mesh Pro) but again, some of the transitions work and some don't.

This problem is also present in the pause menu but unlike the main menu, none of the buttons can be selected there. I even used Debug.Log to check and see if the first button is selected and it was; but still the animation transition doesn't work.

I believe that this is a Unity bug but I decided to ask it here just to see if I'm missing something.

Thank you in advance.

\$\endgroup\$
12
  • \$\begingroup\$ Maybe first try with a different Unity year-version to see if this is a Unity bug. \$\endgroup\$ Feb 8 at 13:51
  • \$\begingroup\$ Also try setting selected game object in the next frame after you set it to null. Sometimes lifecycle of Unity UI object messes things. (That is, try calling EventSystem.current.SetSelectedGameObject(exitPanelClosedButton); next frame using a Coroutine of 1 frame and see if it helps). \$\endgroup\$ Feb 8 at 13:55
  • \$\begingroup\$ Thank you for commenting! I upgraded my version from 2020.3.24f1 to 2020.3.27f1 but that didn't help. If I upgrade or downgrade to a different year, the project will most likely be messed up. Also, about using a Coroutine, I'm not sure if that can fix the problem since the working buttons don't use it but I'll give it a try. I need to start it in OpenExitPanel function because the exit panel can't be closed now. I wrote something and updated the code but it's not working. Is it possible to tell me what part of the code is wrong? I'm not the best at coding :) \$\endgroup\$
    – Ali
    Feb 9 at 19:36
  • \$\begingroup\$ You are welcome. You can (should) try a different year version on a copy of the project in a separate folder. Otherwise, you can revert via git but the Library gets messed up. Your coroutine looks fine so the problem should be something else (I had a similar issue with dropdown animations and next frame trick had solved the issue). In some cases recreating the object from the scratch, or deleting the broken one and copying a working one could help. \$\endgroup\$ Feb 10 at 12:34
  • \$\begingroup\$ Another question, is the "Yes" button clickable (i.e. functional except the color animation)? If the game object order in the hierarchy is incorrect the pop-up menu background may be blocking the UI hover and click. This could be the case if the background image is on the parent game object. If this is the case make an empty parent, and order background and buttons as its child game objects where the background game object is the first child. \$\endgroup\$ Feb 10 at 12:37

1 Answer 1

0
\$\begingroup\$

The solution was simple. I forgot to assign the function in the On Click() function in the inspector of the quit button. I mistakenly had assigned SetActive() function. Now it works.

PS: Be sure to use the code in the question. There is no need to use the coroutine for making this to work.

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .