Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

Getting a State value in Unity

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

asked Dec 2, 2020 in General Discussion by Mads Maretty S. (Audiokinetic) (35,370 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".

    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)
                print("Set State02"); // just delete if you've tested it out.
            else if (currentState == State02.Id)
                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. 

answered Dec 2, 2020 by Mads Maretty S. (Audiokinetic) (35,370 points)