Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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

Discussion in 'UGUI & TextMesh Pro' started by Manou1111, Sep 18, 2018.

  1. Manou1111

    Manou1111

    Joined:
    May 13, 2017
    Posts:
    13
    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.
     
  2. Manou1111

    Manou1111

    Joined:
    May 13, 2017
    Posts:
    13
  3. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    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.
     
    Last edited: Sep 20, 2018
    Dani1113 likes this.
  4. Manou1111

    Manou1111

    Joined:
    May 13, 2017
    Posts:
    13
    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.)

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.EventSystems;
    4.  
    5. // Class that prevents button from being in "Highlighted" state after being in "Disabled" state
    6. public class ButtonBugFix : MonoBehaviour, IPointerExitHandler
    7. {
    8.     // mouse event
    9.     public void OnPointerExit(PointerEventData eventData)
    10.     {
    11.         Fix();
    12.     }
    13.  
    14.     // joystick and keyboard event
    15.     void Update()
    16.     {
    17.         if (Input.GetButtonDown("Submit"))
    18.         {
    19.             Fix();
    20.         }
    21.     }
    22.  
    23.     // fix button state
    24.     public void Fix()
    25.     {
    26.         GetComponent<Button>().enabled = false;
    27.         GetComponent<Button>().enabled = true;
    28.         GetComponent<Animator>().SetTrigger("Normal");
    29.     }
    30. }
    31.  
    32.  
    edit : add this on your buttons

    Hope it helps !
     
  5. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    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.
     
  6. Dani1113

    Dani1113

    Joined:
    Mar 5, 2021
    Posts:
    1
    Your second option worked for me, thanks
     
  7. GlennZundel

    GlennZundel

    Joined:
    May 11, 2019
    Posts:
    2
    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
     
  8. murilohue779

    murilohue779

    Joined:
    May 15, 2023
    Posts:
    7
    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