Setting Switches (24.1) - alessandrofama/wwise-godot-integration GitHub Wiki

Switches are a type of Game Sync that enable the implementation of variations for specific sound objects. They are commonly used for features like multi-surface footstep sounds, where different sets of sounds are played based on the surface the player is walking on. Unlike States, Switches are applied at the local game object level, meaning they can be unique for each instance of a game object.

Setting Switches with the AkSwitch Node

The integration provides a custom node called AkSwitch, which allows you to set Switches easily:


wwise-godot-ak-switch-inspector

The AkSwitch node has the following properties:

  • Switch: The Switch you want to set selected from the Wwise Picker window
  • GameObject: Specifies the GameObject in the Scene Tree on which the Switch should be set (this could be an AkEvent3D for example, or another Node you posted an Event on).
  • Trigger On: Specifies when the Switch should be set (e.g., None, Enter Tree, Ready, Exit Tree).

To use the AkSwitch node, select the desired GameObject from the Scene Tree and fill out the other properties accordingly.

Triggering a AkSwitch node with GDScript

If you selected None in the Trigger On property, you can decide to set the Switch by referencing the AkSwitch Node in a script, and call its set_value function.:

func _ready():
	$AkSwitch.set_value()

Setting Switches with GDScript

To set a Switch using GDScript, you can use the WwiseSwitch type in a script, or call directly the exposed set_switch function in the Wwise singleton.

Using the WwiseSwitch Type

When you export a WwiseSwitch type variable in a script, a button will appear in the inspector, allowing you to select your desired Switch from the Wwise Picker:


wwise-godot-ak-switch-inspector

Select a Switch and then call set_value on the exported WwiseSwitch variable, providing a GameObject to the function:

extends Node

@export var switch:WwiseSwitch

func _ready() -> void:
	switch.set_value($AkEvent3D)

Setting a Switch using the set_switch function in the Wwise singleton

Alternatively you can use the set_switch or set_switch_id functions provided by the Wwise singleton:

Using switch names:

func _enter_tree():
	Wwise.set_switch("Footsteps", "Water", game_object)

Using switch IDs:

func _enter_tree():
	Wwise.set_switch_id(AK.SWITCHES.FOOTSTEPSSWITCH.GROUP, AK.SWITCHES.FOOTSTEPSSWITCH.SWITCH.WATER, game_object)

The set_switch functions take the Switch Group and Switch Value as names or IDs, along with the game_object on which the Switch should be set. If you have generated the Wwise IDs, you can access them by referencing the AK class.

⚠️ **GitHub.com Fallback** ⚠️