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 /
avatar image
2
Question by NatalSJ · Feb 20, 2017 at 09:43 AM · ui3dplayerprefstoggleimage effects

Changing Toggle UI's value (Checked or Unchecked)

I can't seem to find a way wherein we can change the value of the Toggle UI.

Setting it to checked or unchecked. I wonder if it's really impossible or I'm just missing something.

Why I need it?: I'm developing a 3D Game where there are ImageEffects such as Bloom, Motion Blur, and Antialiasing. And I have a pause menu with settings that toggles those ImageEffects to turn it on or off.

Somehow, I wanted it to be saved in PlayerPrefs so once an ImageEffect is off, it will stay off once you open the game again.

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

5 Replies

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

Answer by JaredHD · Feb 20, 2017 at 06:44 PM

You use .isOn to set the value. E.G

 using UnityEngine;
 using UnityEngine.UI;
 
 public class HelpSomeone : MonoBehaviour
 {
     GameObject inGameToggle;
 
     private void Start()
     {
         inGameToggle = GameObject.Find("Toggle Name");
     }
 
     //Use buttons linked to this
     public void ChangeValueToTrue()
     {
         inGameToggle.GetComponent<Toggle>().isOn = true;
     }
 
     //Use buttons linked to this
     public void ChangeValueToFalse()
     {
         inGameToggle.GetComponent<Toggle>().isOn = false;
     }
 
 }
Comment
Add comment · Show 3 · 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 NatalSJ · Feb 20, 2017 at 06:49 PM 0
Share

Ohhh! Why didn't I see that! This is perfect. Thank you! :)

avatar image JaredHD NatalSJ · Feb 20, 2017 at 06:58 PM 0
Share

Not a problem :p Good Luck

avatar image bramd91 · Nov 29, 2021 at 10:20 PM 0
Share

I know that this is an old question but I still wanted to address one more issue. When setting the isOn on the toggle, the value was correct but the pressed color that I specified was not showing. I had to call the Select() on the Toggle component to make sure that next to being 'isOn' it also showed as a selected toggle color.

avatar image
5

Answer by Jan_Sch · Feb 21, 2017 at 09:48 AM

I think it's something like

 toggle.isOn = true
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 $$anonymous$$ · Feb 20, 2017 at 10:19 AM

yes, it is possible. use bool var for every image-effects so every time when open the game set-get player pref for image-effects.

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 NatalSJ · Feb 20, 2017 at 05:35 PM 0
Share

$$anonymous$$ay I know what's the syntax for changing the Toggle UI?

Fore example, I have a Toggle variable: $$anonymous$$otionBlurToggle.

Is there something like: $$anonymous$$otionBlurtoggle.checked = true;

avatar image Vivien_Lynn NatalSJ · Mar 08, 2020 at 04:55 PM 0
Share

I am not exactly sure what you are asking for, but I hope this answers your question:

 // This will show you the state of your toggle in the console
 bool toggleState;
 $$anonymous$$otionBlurtoggle.isOn = toggleState;
 Debug.Log(toggleState);
 
 
 // This will toggle your Button on and off
 $$anonymous$$otionBlurtoggle.isOn = !$$anonymous$$otionBlurtoggle.isOn
 // Simply put: Turn my Toggle-State into what it is not
 // So if on, turn it off. If off, turn it on


avatar image
0

Answer by codemaker2015 · Sep 01, 2021 at 03:30 PM

You can use isOn attribute to check whether the toggle button is checked or not. Also, set the isOn attribute to toggle the button.

  using UnityEngine;
  using UnityEngine.UI;
  
  public class ToggleDemo : MonoBehaviour
  {
      [SerializeField]
      private Toggle toggle;
  
      private void Start()
      {
          Debug.Log("Toggle button status: " + toggle.isOn);
      }
  
      public void ChangeToggleTrue()
      {
         toggle.isOn = true;
         Debug.Log("Toggle button status: " + toggle.isOn);
      }
  
      public void ChangeToggleFalse()
      {
         toggle.isOn = false;
         Debug.Log("Toggle button status: " + toggle.isOn);
      }
  }

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 Must_I_have_a_name · Apr 09 at 10:53 PM

There is a place where you should not change the .isOn value. That place is in a function which is triggered by a user clicking on the toggle. Do not monkey around the associated .isOn value THERE. There's a race condition. Instead put a check in Update to see if you should change isOn for a toggle. If you try to change the isOn of a toggle in a function caused by a user click it may or may not work

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unlockable Levels 3 Answers

Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer

Why are my UI images appearing in front of my 3D objects 2 Answers

How can I collect playerprefs values? 0 Answers

Is there a better way to access the single active Toggle in a ToggleGroup? 4 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