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
2
Question by annunciation · Jun 25, 2017 at 02:14 AM · slider

How can I use a slider's UnityEvent "On Value Changed" to send the slider's current value to a script?

I can not get the On Value Changed function on a slider to pass its changed value to a function. It will only ever send the value that is displayed in the input field. The manual says that it is supposed to send its changed value as an argument to the function but it is not doing that for me.

Currently, the slider has a min value of 0, max value of 10, and a default value of 0.

alt text Screenshot of the settings

The function that is being called is just this:

 public void MainVolumeControl(float vol){
      Debug.Log ( "vol is: " + vol );
 }

The manual states that the On Value Changed "... event can send the current value as a float type dynamic argument. The value is passed as a float type regardless of whether the Whole Numbers property is enabled."

That is just not happening. It will only ever pass what is in the last input field on the Event section - 0 in the screen-shot. If I put "3" than 3 will be the only thing passed to the function no matter what the sliders value is.

So, what am I doing wrong or is the manual wrong?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
10

Answer by DarkGate · Mar 10, 2019 at 04:11 AM

![alt text][1]From the thread above, credit goes to Jesper.

Make sure you selected Dynamic float from the OnValueChanged drop down list in the inspector

See image: https://imgur.com/5325W7m

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
2

Answer by benio33 · Jan 09, 2020 at 05:35 AM

It is an old thread, but maybe someone will find this clarification useful, since I feel like noone made it clear enough at least ... I had to scratch my head for a bit how to bring in the "dynamic float" variables, this is how you do it.

Instead having your function declared like this:

  public void MainVolumeControl(float vol){
       Debug.Log ( "vol is: " + vol );
  }


You should declare it like this:

  public void MainVolumeControl(System.Single vol){
       Debug.Log ( "vol is: " + vol );
  }

That way you your "MainVolumeControl" method will show up in the menu as "dynamic float" and when you chose it from the dropdown menu the slider values will be passed automatically to the function upon value changed

Hope this helps.

Cheers, M.

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 unity_PNVpFX7xnCpieQ · Nov 07, 2020 at 10:25 AM 0
Share

Thanks so much for the clarification. Also note that your method will show up in both places, in the Dynamic Float section and the Static Parameter. $$anonymous$$ake sure you pick the Dynamics Float as mentioned previously. alt text

screenshot-2020-11-07-022422.png (12.7 kB)
avatar image michelepiccolini · Jan 31 at 01:03 PM 0
Share

This is so interesting and so important! But where TF is this documented? Is there any page on the documentation that talks about this difference and how to implement callbacks with dynamic parameters as opposed to static ones?

avatar image
1

Answer by Mr-Men · Jul 13, 2017 at 10:37 AM

@annunciation, this worked for me - https://stackoverflow.com/a/32680604

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 Babelguppy · Jun 15, 2020 at 09:44 PM 0
Share

Had to use "using UnityEngine.UI" to my script to be able to use the Slider type, but this worked for me.

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

112 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 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 avatar image avatar image avatar image avatar image

Related Questions

How do I take out a UI Slider's value? 0 Answers

lerp a float value of keyup 2 Answers

Click option is not working in GameView with some different clicker 0 Answers

Slider value help 0 Answers

Make a 2D side panel in a 3D game 1 Answer


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