Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 kr77 · Aug 30, 2014 at 06:41 PM · c#uitogglebeta

[Unity3d beta 4.6] Make Active for UnityEngine.UI.Toggle

I am playing around with the 4.6beta and UnityEngine.UI. I have a ToggleGroup setup and I want to select a toggle in code after I load some PlayerPrefs for which toggle was selected last time.

I found the toggle that I want to activate, but I do not know how to make it active. I looked through the scripting reference for Toggle and ToggleGroup but I do not see any call that accomplishes this. I thought that UnityEngine.UI.ToggleGroup.NotifyEnabled(Toggle t) would do it, but that did not work.

It is possible that sending a ToggleEvent is required... but I do not quite understand the eventing system in Unity enough to evaluate that option.

Does anyone know how to tell a toggle to become active in code?

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

2 Replies

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

Answer by AyAMrau · Aug 31, 2014 at 08:35 PM

NotifyEnabled seems to only be used to inform the group that the Toggle is enabled.

So if you want to actually change a state of a single Toggle you just change it's isOn value:

 toggle.isOn = true;
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 kr77 · Aug 31, 2014 at 09:19 PM 0
Share

I think I was writing my rant and didn't reload the page. Thanks for the more concise answer. I'm check marking yours. I submitted my comments to the feedback site.

avatar image wrenagade · Dec 02, 2015 at 09:53 AM 1
Share

Setting this does not work 100%.

I have a toggle group and when selecting a toggle in code after I load some the value from PlayerPrefs only the check for the toggle is set properly.

I have 3 toggles and each toggle has a different transition color tint. When setting the toggle in code, the check mark is set properly with the correct color tint but the background sourceImage color tint is not.

The background sourceImage color tint is only set when pressing the toggle.

avatar image
1

Answer by kr77 · Aug 31, 2014 at 08:47 PM

I found the answer to my own question just a moment ago. I needed to set the Toggle.isOn property to true. The name confused me. I bypassed the property due to assuming that it was a function that returned a bool; like EventSystems.UIBehaviour.IsActive or UI.Selectable.IsInteractable.

At this time the documentation for the Toggle.isOn call is:

Is the toggle on.

This sounds like a method that returns a bool, but then it is clearly referenced as an actual bool property when you click into it. Maybe a better label could be used to identify it as an actual value. Like 'selected' which would be like the enabled property on many Unity objects.

After looking for instances of properties and methods starting with 'is', there appears to be no standard usage of the word 'is' in naming. The word 'on' for example has the standard usage of being a method that reacts to an event.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

[4.6] Toggle/Checkbox On/Off 1 Answer

Use a toggle button to change a GameObjects visibility 2 Answers

Toggles/Toggle Groups Question 0 Answers

Cant access .interactable 1 Answer

Toggle UI 4.6 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