Community Q&A

Welcome to Audiokinetic’s community-driven Q&A forum. This is the place where Wwise and Strata users help each other out. For direct help from our team, please use the Support Tickets page. To report a bug, use the Bug Report option in the Audiokinetic Launcher. (Note that Bug Reports submitted to the Q&A forum will be rejected. Using our dedicated Bug Report system ensures your report is seen by the right people and has the best chance of being fixed.)

To get the best answers quickly, follow these tips when posting a question:

  • Be Specific: What are you trying to achieve, or what specific issue are you running into?
  • Include Key Details: Include details like your Wwise and game engine versions, operating system, etc.
  • Explain What You've Tried: Let others know what troubleshooting steps you've already taken.
  • Focus on the Facts: Describe the technical facts of your issue. Focusing on the problem helps others find a solution quickly.

0 votes

Original question posted on Wwise Wwizards and Wwitches

Posted by Benedict S.
Hey everyone, got what might be a really simple Unity integration question. I'm trying to toggle between engine states "on" and "off" using one key, and I'm trying to check what the current state is before setting it to the other. I'm struggling to work out what do here – I've tried using akSoundEngine.GetState(), but I have no idea how to use it.
The first parameter is the state group as a string, but the second is "out uint out_rState" according to VS Code. I'm not great with Unity, so I'm wondering what on earth this integer might be that I need to feed in – does anyone have any ideas?
Here's the one page I've found so far which even mentions akSoundEngine.GetState(). Cheers

in General Discussion by Mads Maretty S. (Audiokinetic) (40.2k points)

1 Answer

0 votes

Hello Benedict, 

Originally, I advised you to use Wwise-Types, but that was a mistake. Wwise-type States are just specific State values and so there's no GetValue or GetState function on it. That said, you can still create two Wwise-type States, which would give you the pickers in the Inspector, and then get the Group ID from it. Something like this... 


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SomeScript : MonoBehaviour
{
    public AK.Wwise.State State01;
    public AK.Wwise.State State02;
    private void Start()
    {
        // If not set, the initial State will be "None".
        State01.SetValue();
    }

    void Update()
    {
        // Button input check
        if (Input.GetKeyDown(KeyCode.Space)) {            

            uint currentState = 0; // variable to store the ID in.
            // Since the Wwise-types only refer to specific state values,
            // you will need to AkSoundEngine.GetState() to get the global one.
            // That said, you can still use the ID from the Wwise-Types.
            AkSoundEngine.GetState(State01.GroupId, out currentState);
            print(currentState); // just delete if you've tested it out.

            if (currentState == State01.Id)
            {
                State02.SetValue();
                print("Set State02"); // just delete if you've tested it out.
            }
            else if (currentState == State02.Id)
            {
                State01.SetValue();
                print("Set State01"); // just delete if you've tested it out.
            }
        }
    }
}


As for the 'out uint out_rState' you just need to declare a uint property first, so you can store the value you get back. That value will be the ID of that State, and you can e.g. use it to search in your SoundBank.txt file and see what specific State it is. 

by Mads Maretty S. (Audiokinetic) (40.2k points)
...