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
1
Question by justinhj · Dec 08, 2014 at 05:33 AM · ui

UI.Toggle set to isOn initial state on exit

When I hit play in the editor I want to load an int from playerprefs to determine if the music should play. If the user toggles a Toggle then I start or stop the music and update the playerprefs then save them.

However, when I exit the application the Toggle gets a value change message and the isOn value will not be set to whether the user change it or not, it will be always set to the initial value of the toggle.

This means if the user exits the app while a toggle is active it screws up the prefs.

Any workarounds?

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 Hoorza · Nov 23, 2017 at 10:38 PM 0
Share

I have found myself in the same situation and after 4 hours of trying, searching and typing I am close to $$anonymous$$rs, this should be so simple. This is nonsence. I can't believe this has been a bug or a problem for past 3 years. I am using toggle.IsOn to check when the scene loads up at which state toggle should be but it still gives me wrong results. I am using print command at each step of the code and I have noticed that my Toggle function gets called when i depress play button in Unity editor. Something is retarded or I am. If anyone knows what I am doing wrong please do tell me. Cheers

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Fragmental · Jun 19, 2018 at 04:28 PM

I know this is four years late, but I may have an answer. It's hard to tell if your problem is the same from the information your provided, but maybe this will help.

When I set the toggle states in "start", it automatically triggers the "On Value Changed" event, if the new toggle bool value is different than what was set in the inspector. This calls a method I had attached in the inspector, which caused undesirable results.

I found a solution. I don't know if it's the best solution, but it seems to work without any issues. I've outlined my problem and solution in more detail here. https://answers.unity.com/questions/1519824/undesirable-call-of-toggles-on-value-changed-when.html

The tl;dr is that I removed the method call from the "On Value Changed" Event, in the inspector, and then added an "Event Trigger" Component with a "Pointer Click" event and used that instead.

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

27 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

Related Questions

Unity 2D 4.6b UI: Why are instantiated prefab sprites rendering over UI elements? 1 Answer

How to keep same amount of content on different canvas sizes 0 Answers

New UI batching problem 1 Answer

New UI button OnClick() how to "send message" with parameters? 3 Answers

Unity 4.6.1 text error/bug (unreadable text) 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