Wwise RTPCs are useful for making changes to our Wwise sound objects by using game variables. In this tutorial we will create a RTPC in Wwise to control the pitch setting of a sound. We will then set the RTPC to an arbitrary value at runtime in Unity.
Creating a RTPC in the Wwise Authoring Tool
To create a RTPC in Wwise, select a sound object in the Actor-Mixer-Hierarchy, right click on the pitch setting and select Add RTPC->Game Parameters->New:
Give the Game Parameter a new name and you will presented with the RTPC view of the sound object:
By default Game Parameters have a value range between 0 and 100 with a default value of 50. If we want to change the range setting we can switch to the Game Syncs tab and select the appropriate Game Parameter. The Game Parameter Property Editor will show up:
Alternatively, we can also directly double click on the Game Parameter in the RTPC tab of the Sound Property Editor:
I will select a range between -12 and 12 with a default value of 0. Furthermore, I set the min value of the Game Parameter to -1200 and the max value to 1200. 1200 cents are the equivalent of an octave in Wwise:
Controlling a RTPC in Unity by using AkSoundEngine.SetRTPCValue
The simplest way to control a RTPC value is to use the SetRTPCValue
method of the AkSoundEngine namespace. In general the code looks like this:
AkSoundEngine.SetRTPCValue("GameParameter", value, gameObject);
The first parameter of the SetRTPCValue method is a string referring to the name of the RTPC. The second parameter is a float variable. Set this to the value you want to set the RTPC to. The third parameter is the GameObject we want our RTPC to act on.
If you want to set the RTPC value on a global scope, replace the GameObject argument with AK_INVALID_GAME_OBJECT
.
Controlling a RTPC in Unity by using the AK.Wwise.RTPC Type
To declare a Wwise RTPC Type add following code line at the start of your class:
[SerializeField]
private AK.Wwise.RTPC rtpc = null;
We can select the appropriate RTPC value in Unity’s inspector:
After that we can set the RTPC value my calling the SetValue
method of the Wwise.RTPC type:
rtpc.SetValue(gameObject, value);
If you want the RTPC to have effect on a global scope, call SetGlobalValue
instead:
rtpc.SetGlobalValue(value);
To test the RTPC created above declare a float value with a range attribute between -12 and 12 at the start of the class:
[SerializeField] [Range(-12f, 12f)]
private float pitchParameterValue = 0;
A slider will show up in Unity’s inspector:
Start the scene, make sure to have an Event playing a sound affected by the RTPC on the GameObject and move the pitch parameter value slider, you will hear the changes in pitch taking place. That’s it! You learned how to control RTPCs in Unity. Check out the tutorials about setting Wwise Switches in Unity or setting Wwise States in Unity.