Skip to content

Setting States

Alessandro Famà edited this page Dec 13, 2023 · 2 revisions

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.

Setting States with the AkState Node

The integration provides a custom node called AkState to easily set States:



wwise-godot-ak-state-node-inspector

The AkState node has the following properties:

  • State Group: Selects the desired state group.
  • State Value: Sets the desired state value within the selected state group.
  • 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 group, state value, and the trigger on callback.

Triggering a AkState node with GDScript

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_state:

func _ready():
	$AkState.set_state()

Setting State with GDScript

To set a State using GDScript, you can utilize the set_state or set_state_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.