[Solved] Changing the pitch of AudioMixer by code

Hi,

Can we change the pitch of an AudioMixer by code (C#)? We can from the inspector.
It’s seems like the AudioMixer object don’t have any method for this.

Thank you.

2151049--141998--Capture.PNG

2 Likes

You have to expose the Pitch parameter to script control. Right click on the parameter name “Pitch” and choose “Expose ‘Pitch’ to script”. Give it a name in the Exposed Parameters drop down on the AudioMixer view in the editor. Then you can use mixer.SetFloat(“myParameterName”, 0.5f); to change the value from one of your scripts.

12 Likes

Thank you for your response!

If someone is looking where the dropdown is, here is a picture that shows.

8 Likes

Thank you both for the information relating to finding the exposed parameters - that was quite a search! :slight_smile:

2 Likes

Is this not what I should do?
8152319--1059113--upload_2022-5-24_8-20-25.png
exposer param:
8152319--1059116--upload_2022-5-24_8-20-38.png

I get this error on the “.5f”:
8152319--1059122--upload_2022-5-24_8-21-31.png

8152319--1059110--upload_2022-5-24_8-20-15.png
8152319--1059122--upload_2022-5-24_8-21-31.png

1 Like

You just need to declare a float variable to put the retrieved value into:

float myPitchValue;

audioMixer.GetFloat("pitch", out myPitchValue);

print("myPitchValue: " + myPitchValue.ToString());
1 Like