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
5
Question by CptCheerios · Apr 11, 2015 at 02:07 AM · uieventtoggle

Toggle Event passing bool [4.6+]

So by reading the documentation for a toggle it says this "The Toggle has a single event called On Value Changed that responds when the user changes the current value. The new value is passed to the event function as a boolean parameter."

What this means to me is that I should be able to assign a function that receives a boolean parameter and it will pass it but this does not occur.

Simple function I would assign is like this

public void ToggleChanged(bool Value) { Debug.Log(Value); }

When assigned to the event I am only able to assign the value, so its either always going to be false or true, its not going to be the value which it has changed to.

So my question is what is the proper syntax for the function, I can't find any documentation on this.

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
11
Best Answer

Answer by Khaled-Khair · Feb 20, 2016 at 12:40 PM

Make sure you select the method located under the "Dynamic bool" header.

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 FurretTurret · Apr 12, 2016 at 07:40 PM 3
Share

To clarify, this is on the dropdown from which you select what function to call.

avatar image LilGames · Oct 03, 2017 at 02:59 AM 0
Share

@CptCheerios , accept $$anonymous$$haled's answer already!

avatar image Bunny83 LilGames · Oct 03, 2017 at 03:06 AM 0
Share

The OP hasn't been seen since march 2016. So it's unlikely he will respond to your comment. Anyways i'll accept the answer.

avatar image LilGames Bunny83 · Oct 03, 2017 at 03:36 AM 0
Share

Thanks. This is one of those Answers that has high Google search rankings and the only one that clarifies where the Dynamic Bool is located.

avatar image
0

Answer by YoungDeveloper · Apr 11, 2015 at 02:13 AM

All what you get from toggle is the event. Passing bool manually will result in constant value as it's a hard-coded parameter. Of course you can set it by code, but in this case it's unneeded.

Instead, cache the toggle component;

 using UnityEngine.UI; //include UI namespace before class declaration

 public Toggle toggle; //drag from inspector

And set the event for value changed without parameters.

 public void eventValueChanged(){
     Debug.Log("Toggle is "+toggle.inOn); //check isOn state
 }

I hope i made this understandable.

Comment
Add comment · Show 1 · 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 Xelnath · Mar 02, 2016 at 03:56 PM 0
Share

Also note that isOn will return the value of the toggle BEFORE the change.

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

8 People are following this question.

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

Related Questions

Is there an event other than OnValueChanged for Toggle UI? 0 Answers

Toggle's 'On Value Changed' checkbox is shown for bool parameter function 0 Answers

How to have a callback when a toggle is clicked in a toggle group? 3 Answers

Is there a way to know when mouse is 'hovering' over a Toggle? 2 Answers

How do I get a toggle to dim its text when it's not "interactable"? 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