Wwise States are a type of Game Sync that allow us to make changes to audio based on predefined global states that are assigned to audio objects and then are triggered in-game. States can be used to change mix settings in response to an event happening in-game for example. In a music system containing musical segments, States are preferred over Switches, since they act on a global scope. To learn more about game object scopes, read the documentation article here: Understanding Global and Game Object Scope.
Setting a Wwise State by using the Set State node in Blueprints
We can use the Set State node provided by the Wwise intergration plugin to set a State in Unreal Engine 4:
StateGroup is the State Group created in the Wwise authoring tool and stateValue is the State we want to actually set. Since States are applied on a global scope and not on individual Game Objects like Switches, there is no need to connect an Actor to a node pin.
Setting a Wwise State with C++ code
We can call the SetState
function of UAkGameplayStatics
to directly set a State in code:
UAkGameplayStatics::SetState(FName("PlayerState"), FName("Dead"));
The first argument of the SetState function is the State Group created in the Wwise authoring tool, the second one the actual State we want to set.
Alternatively, we can directly interface with Wwise’s sound engine to set a State:
FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
if (AudioDevice)
{
AudioDevice->SetState(*FName("PlayerState").ToString(), *FName("Dead").ToString());
}