Button in Highlighted state instead of Normal when going back from Disabled

Hello there !

Ok let’s say I have 2 panels :

  • I press a button from panel 1
  • it displays panel 2 and set panel 1 to not interactable (canvas group)
  • I press the back button in panel 2
  • it displays panel 1 but the first pressed button is in “Highlight” state instead of “Normal”

I use the On Click () feature in Button inspector to make these actions.

Is that a bug or I miss something maybe… ?

Regards,
P.

Ok looks like it’s a bug : Clicking a button leaves it in MouseOver state

It’s been like this for years, there are many thread with people trying to fix it and there’s even a bug report that’s been marked as “fixed” (even though it’s not - at least not in 2017.3.1f1). I contacted the support about it and according to them:

“…this is by design and it doesn’t seem like the behavior will be changed any time soon…”

What you can do about it:

  • Change the color back to “Normal” yourself
  • Set the button’s “Navigation” to “None”. This also means that you can’t use your keyboard or controller to navigate to or from the button and you won’t get a proper object from the EvenSystem (possibly even “GameObject.Find”). Also: “None” won’t fix it for touchscreens, I had to…
  • Set the highlighted color to the normal color

It sucks, I know. It’s probably best to contact the support and hope that they’ll end up fixing it if enough users complain.

1 Like

Hey thanks for the answer SimRuJ !

Based of answers here : click
I wrote this code, it works with joystick and mouse;

(bug : if you click on the mouse and move the joystick at the same time, joystick navigation is not working anymore.)

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

// Class that prevents button from being in "Highlighted" state after being in "Disabled" state
public class ButtonBugFix : MonoBehaviour, IPointerExitHandler
{
    // mouse event
    public void OnPointerExit(PointerEventData eventData)
    {
        Fix();
    }

    // joystick and keyboard event
    void Update()
    {
        if (Input.GetButtonDown("Submit"))
        {
            Fix();
        }
    }

    // fix button state
    public void Fix()
    {
        GetComponent<Button>().enabled = false;
        GetComponent<Button>().enabled = true;
        GetComponent<Animator>().SetTrigger("Normal");
    }
}

edit : add this on your buttons

Hope it helps !

I posted in the thread you linked (very last post) but completely forgot about it because I’ve been using “None”. There’s a shorter way:

This way the button should get unselected, even with the navigation set to “Automatic”. I haven’t tested it with a touchscreen yet though.

Your second option worked for me, thanks

Hey,
I’ve had a similar Issue, the only difference being that my button is set to Transition: Animation.
I fixed it by defining a “Normal” and a “Selected” Animation. Those just set the Properties of the button to look the way it did before being pressed.
hope this helps

Yeah thank you that worked, my theory is that when an object is set to not active the animation freeze and that object become that specific frame