Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
3
Question by Sinusgamma · Mar 23, 2016 at 05:53 PM · toggleinterfacesaveload

Set a Toggle active in ToggleGroup via script

I want to save / load menu settings, and I have some problem with togglegroup.

Example:

ToggleGroup - Toggle1 - Toggle2 - Toggle3

When user saves the settings I save the name of the active toggle in a serializable, where I have: string toggleName = Toggle2; for example.

By default the togglegroup shows the default active toggle, but I want it to change programatically (i prefer c#) from the loaded toggleName string, but the ToggleGroup seems to lack this feature.

So is there some best practice to do it, maybe my approach is wrong?

Thanks

Comment
Add comment · Show 2
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 achimmihca · Mar 25, 2016 at 08:07 PM 0
Share

I am having exactly the same issue and can't see an obvious solution

avatar image Chris_Entropy · Sep 06, 2016 at 05:18 PM 0
Share

Great, I now have the same problem, but as it seems there is no simple solution to find for this bs.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Farresto · Mar 28, 2017 at 08:50 PM

I've run into the exact same problem today.

I have a list of user profiles for player to select (so there's only 1 single active profile at any given time), but when you return to the profile selection screen, I wanted the selected profile to be already selected/highlighted.

There's no elegant solution I could think of, but what I did was something like:

 // Set an int instead of a string whenever I save the current selected profile:
 PlayerPrefs.SetInt("selectedProfile",0);
 
 
 // And when loading the scene:
 private int selectedProfile;
 
 selectedProfile = PlayerPrefs.GetInt("selectedProfile");


 // Then I find the parent that will have the list of profiles (you can use any other method here, it depends on how you assemble the list):
 ContentSizeFitter rowheader = FindObjectOfType<ContentSizeFitter>();


 // And then, because my list creation always follows the same pattern, the int selectedProfile will always be equal to the child created (and if not, you can just add a +1 or whatever):
 rowheader.transform.GetChild(selectedProfile).GetChild(0).GetComponent<Toggle>().isOn = true;


There might be a proper "best practice" here, but I needed to get this done super fast and move on, so this will be it.

It's been a year since you posted this, but seeing that there's no answer yet, perhaps this might help the next guy looking for it.

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 unity_rhELxLN6lqNVIw · Apr 13, 2021 at 12:11 PM

@Sinusgamma I'm not sure that this would achieve what you want.. but if you have a number of toggles assigned to a toggle group, setting one of the to on would set the other ones automatically to off. All what you need to do is to set the toggle you want to on ToggleName.isOn = true and the others will be turned off automatically. Hope this helps.

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

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

How to save the state of Canvases/Toggles? 1 Answer

Help with Arrays - Check if only 1 is toggled 2 Answers

Toggling checkbox in toggle in GUILayout.Toggle 1 Answer

How to add script to onvaluechanged of toggle of a prefab on runtime? 1 Answer

Unity interface messed up after crash 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