Setting States (24.1) - alessandrofama/wwise-godot-integration GitHub Wiki
States are a type of Game Sync that enable changes to audio based on predefined global states assigned to audio objects and triggered in-game. States are commonly used to modify mix settings in response to in-game events. In a music system with musical segments, States are preferred over Switches because they act on a global scope. To learn more about game object scopes, refer to the documentation article on Understanding Global and Game Object Scope.
The integration provides a custom Node called AkState
to easily set States:
The AkState node has the following properties:
- State: Selects the desired State from the Wwise Picker.
- Trigger On: Specifies when the state should be set (e.g., Enter Tree, Ready, Exit Tree).
To use the AkState Node, select the desired State and the trigger on callback.
If you left the Trigger On
property of an AkState node to None
, you can trigger setting the state by referencing the node and calling set_value
:
func _ready():
$AkState.set_value()
To set a State using GDScript, you can use the WwiseState
type in a script, or call directly the exposed set_state
function in the Wwise
singleton.
When you export a WwiseState
type variable in a script, a button will appear in the inspector, allowing you to select your desired State from the Wwise Picker:
Select a State and then call set_value
on the exported WwiseState
variable:
extends Node3D
@export var state: WwiseState
func _ready() -> void:
state.set_value()
Alternatively you can use the set_switch
or set_switch_id
functions provided by the Wwise
singleton:
Using State names:
func _enter_tree():
Wwise.set_state("MusicState", "Calm")
Using State IDs:
func _enter_tree():
Wwise.set_state_id(AK.STATES.MUSICSTATE.GROUP, AK.STATES.MUSICSTATE.STATE.CALM)
The set_state
functions take the State Group
and State Value
as names or IDs. If you have generated the Wwise IDs, you can access them by referencing the AK class.