Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
33
Question by justin35f · Dec 15, 2014 at 12:52 AM · uibuttons

Unity 4.6 UI button highlight color staying after button clicked

I have a standard UI Button within a panel, and a different color for each of the transition states, to make it easy to identify which state it is in. Each state works as intended, except after I click on a button, the state transitions from the 'Pressed Color' back to the 'Highlighted Color'.

Unfortunately, it persists in this state even after moving the mouse off of the button. Clicking anywhere else within game sets the button back to the 'Normal Color' state.

I have adjusted different properties, but there really aren't that many related properties on a button that would affect this, so I am having trouble with it.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

12 Replies

· Add your reply
  • Sort: 
avatar image
113
Best Answer

Answer by Dezky · Dec 17, 2014 at 01:18 PM

Got the problem too, it's due to the navigation system for keyboard only usage. put navigation on none on your button script and it will work ;)

Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image justin35f · Dec 17, 2014 at 06:30 PM 0
Share

Thanks for the answer, I'll try it out and see if it works for me.

avatar image justin35f · Dec 17, 2014 at 06:43 PM 0
Share

This seems to work, but it's now doing some weird flicker, but I'm not too worried about that. Thanks for the help.

avatar image wang37921 · Mar 09, 2015 at 07:20 AM 0
Share

Thanks. It works.

avatar image Sposito · Jul 01, 2015 at 12:41 PM 7
Share

What if i need to use the navigation system?

avatar image VIC20 · Dec 07, 2016 at 02:40 AM 3
Share

I had this problem with keyboard/game-controller-only usage on mobile.

When the button was pressed I switched to a submenu/page and disabled the button by disabling the parent GameObject for the entire menu. When I returning from the submenu the button would always still be highlighted because the animation of the button never got a chance to finish. The result is that the color of the button will stay forever in highlighted state.

The solution for this problem is to disable the Button (Button.enabled=false;) ins$$anonymous$$d of deactivating the entire GameObject and to disable the Canvas of the Button (Canvas.enabled=false;).

Show more comments
avatar image
22

Answer by Robdon · Feb 16, 2016 at 09:36 PM

Rather than disabling navigation you can do this.

All you need to do is remove the currently selected object from the event system, since technically, the button is then the 'selected' object after clicking it. Its like the windows 'focus' rect around the current field.

 using UnityEngine.EventSystems;
 
 EventSystem.current.SetSelectedGameObject(null);

If you pop that into your buttonpressed script/method, then it will remove the selection and colour immediately.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tzan · Dec 23, 2016 at 10:04 PM 0
Share

This works great! Thanks.

Not sure about that OnPointerExit way mentioned in another answer.

avatar image Akeronz · Apr 03, 2018 at 02:27 AM 0
Share

Worked great for me (Unity 2017, had the exact same issue) and seems better than disabling navigation for sure

avatar image DearUnityPleaseAddSerializableDictionaries · Aug 19, 2018 at 09:05 PM 0
Share

Thanks <3. Love the quick solution!

avatar image kikill · Dec 15, 2018 at 12:41 AM 0
Share

Worked for me as well. Thank you!

avatar image
9

Answer by JuanMaldonado · May 21, 2017 at 06:05 PM

In my case, setting the navigation to NONE didn't work. The solution is to disable and re enable the button component and if you have animations, trigger the "Normal" animation transition.

 GetComponent<Button> ().enabled = false;
 GetComponent<Button> ().enabled = true;
 GetComponent<Animator> ().SetTrigger("Normal");


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mani3307 · Jan 24, 2018 at 10:58 AM 0
Share

This is the correct answer dont disable navigation it has other uses

avatar image browne11 · Mar 02, 2018 at 09:37 PM 0
Share

Thanks this works best in my case too.

avatar image
5

Answer by lermy3d · Aug 27, 2015 at 02:02 PM

Wouldn't this be solved if they include a Hover state?

This will give you full control, you could make the state different from the Highlight state and users do not get confused with two highlighted elements and you can still keep using the keyboard/joystick navigation system.

In this case you could also have the choice to decide whether the button should be different in a hover state or stay the same if you do not want that behavior! :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RogDolos · Oct 21, 2015 at 10:08 PM 0
Share

A better solution would be to simply not leave elements highlighted until the keyboard / joystick is employed while a UI element is interactable. Which is how most applications behave.

Is there any way to globally toggle the navigation system?

avatar image lermy3d · Oct 21, 2015 at 10:27 PM 0
Share

How about when the mouse move over a button triggering the highlight state and then you start using the keyboard, in the way is currently working you will have two highlighted elements.

If you set by default the behaviour you are explaining it would be okey, since is how you said "is like most applications work", but that still does not give the developer a way to create and customize a different user experience.

Having a hovering state allows the developer to control that behaviour without imposing a specific model.

avatar image
5

Answer by RogDolos · Oct 21, 2015 at 10:39 PM

I think most importantly it should work correctly for one input at a time. The navigation features are especially important for those with disabilities using alternate controls (via keyboard interface typically). So making a custom user experience that involves a combo of mouse and keyboard at the same time seems counter-productive to me. This is exactly why I cringe whenever someone suggests the "fix" is to turn navigation off entirely.

Right now though, the way the navigation and hover uses the same highlight just causes confusion in most cases.

For your original suggestion, it could be achieved using an Event Trigger with PointerEnter and PointerExit and apply a temporary overrideSprite as a "hover".

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lermy3d · Oct 21, 2015 at 10:54 PM 2
Share

Exactly, also it could be so awesome if that state were included and took into account as another ui state and shipped with Unity, nevertheless I could make such a script without any problem, if I doit I'll share it. All the best.

  • 1
  • 2
  • 3
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

54 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

4.6 UI Dynamic button event system PointerEnter, PointerExit, PointerUp etc. 1 Answer

Scrolling Scroll Rect with Buttons 4 Answers

possible to change ui buttons sensitivity? 1 Answer

How do I effectively use UI buttons to move my character without confusing assets from the asset store? 1 Answer

Detect if player wants to pause or to jump 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges