Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
2
Question by PsyDev · Nov 10, 2015 at 01:12 PM · uieventsystembuttonstates

EventSystem.SetSelectedGameObject() does not highlight previously selected object

I am using EventSystem.SetSelectedGameObject() to set buttons as selectable and to appear highlighted in my UI. If I switch to a new screen/menu with no selectable items, like maybe an information dialog with only text for example, and then I switch back to the previous screen/menu, when I do EventSystem.SetSelectedGameObject() on the previously selected object, it is not being highlighted.

My guess is that under the hood, the EventSystem is recognizing that the object SetSelectedGameObject is trying to select is already the currently selected one, and therefore not running any "SetHighlighted" function. The object is still actually selectable - if you hit the submit/enter key, it's OnClick function does get called. It just does not get put into a visually highlighted state.

Is this expected behaviour, or have I found a bug?

I have a workaround which is to temporarily set EventSystem.SetSelectedGameObject(null) for one frame, then back to the desired selected object. This seems to force it to set it into highlighted state.

Comment
Add comment · Show 1
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 PrettyBelle · Nov 10, 2015 at 04:36 PM 0
Share

This is happening to me too, I'd really love if someone had an answer ;-; Thanks for the workaround, though. I haven't thought of that. c:

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Southgarden116 · Nov 11, 2015 at 01:16 AM

Maybe you should put the code where you select your gameobject in the OnEnable() function. It gets called whenever an object is becoming active/enabled. If that's not it, where do you call the SetSelectedGameObject() function?

Comment
Add comment · 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
0

Answer by Ipefyx · Jan 25, 2017 at 08:19 AM

I got a similar situation where my initially selected button is not highlighted when I display my menu.

I don't know either if it's a bug or if it's on purpose but you can trick this problem by manually highlight in script when you selected your button.

 EventSystem.SetSelectedGameObject(button.gameObject); // Set button as selected one
 button.OnSelect(null); // Manually call OnSelect transition
Comment
Add comment · 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

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

43 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

Related Questions

Highlight button via script at runtime 5 Answers

Move through selected buttons one by one 0 Answers

EventSystem.current.IsPointerOverGameObject Issues with Mobile 0 Answers

Which UI events propagate? 0 Answers

Canvas appearing over my cursor doesn'tr trigger OnPointerExit ! 0 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