Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
0
Question by Serotonina · Oct 12, 2021 at 03:56 PM · uiinstantiatebuttonseventsystemhighlighting

EventSystem: how to highlight instantiated button?

Hi everyone.

I've structured a Dialogue System that will allow the player to respond NPC's by selecting between multiple answers, thus allowing for branching narratives. The answers the player can choose are instantiated GameObjects UI with a button attached to them that are generated from a list, and the player can navigate the answers using horizontal movement (Keyboard or Gamepad). The player can have a single or multiple answers to choose from, as the system is quite dynamic.

Overall it works well, but I'm stuck with an issue as I can't seem to find a way to highlight the first Gameobject to guide the Player in choosing an answer. Basically what happens is this: the player advance with the dialogue, then a response (or more than one) appear: none of them is selected/highlighted (Ive tried EventSystem.current.SetSelectedGameObject(button);).

The responses gets highlighted only if there are more than one, and only when the player uses the gamepad or keyboard to navigate them (in which case, the selected GameObject is always the last one).

Thanks in advance for your time and answers.

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

1 Reply

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

Answer by swanne · Oct 12, 2021 at 04:40 PM

Hey,

Are you generating the GameObject prefab from a list or array? If so could you utilise the Buttons 'tabIndex' and / or 'spriteState' on object [0]?

https://docs.unity3d.com/2018.2/Documentation/ScriptReference/UI.Selectable-spriteState.html https://docs.unity3d.com/ScriptReference/UIElements.Focusable-tabIndex.html

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 Serotonina · Oct 13, 2021 at 09:50 AM 0
Share

Hi Swanne,

thank you very much for your reply. I've tried to work a bit with both solution but I can't seem to find a way to implement them correctly. I found an interesting discussion here (https://forum.unity.com/threads/accessing-the-selectionstate-of-a-button.992123/) about accessing the Color Tint transitions, so I will probably try this workaround if I can't elaborate anything else.

Thank you for your time!

avatar image swanne Serotonina · Oct 13, 2021 at 01:07 PM 0
Share

You are most welcome. Best of luck in finding a solution

avatar image Serotonina swanne · Oct 19, 2021 at 06:58 AM 0
Share

Hi Swanne,

in the end it was a really noob error on my end. I was keeping in using the "EventSystem.current.SetSelectedGameObject(button);" inside the for loop that was adding the answer to the canvas, instead of outside the loop -_-. Now it works properly.

The issue with accessing the Color Tint transitions still remains, but in the end it was an error by me.

Thanks!

Show more comments

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

239 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 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 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 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 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

How to sense if a button is being highlited from other script. 0 Answers

Why do I have to double click on a button the first time? 4 Answers

Highlight button via script at runtime 5 Answers

EventSystem.SetSelectedGameObject Does not display highlight animations for my buttons 1 Answer

Canvas-prefab elements are not interactable 2 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