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?

1 Like

![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: Imgur: The magic of the Internet

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.

@annunciation, this worked for me - unity game engine - Unity3D Slider onValueChanged sending only 0 (or other defined value) - Stack Overflow