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.

How can I validate a Switch State ID I just attempted to set?

+1 vote

I'm on Wwise version 2021.1.5.7749. I'm looking for a way to validate a switch state ID after setting it.

Switch groups are sometimes set to their default value because of spelling mistakes in the target switch state string. In the Wwise profiler you see the "SetSwitch" call and instead of the requested value you see "Default". (If a default exists it obviously makes sense to apply this value when an invalid value is requested). I'd like to be able to catch those instances.

At the point of setting the switch we call AK::SoundEngine::SetSwitch:

        // Inputs are:
        AkSwitchGroupID targetSwitchGroupID;
        AkSwitchStateID targetSwitchStateID;
        AkGameObjectID gameObjectID;

        // Attempt to change the switch. Note: AK documentation states we *always* returns AK_Success from SetSwitch.
        const AKRESULT result = AK::SoundEngine::SetSwitch(targetSwitchGroupID, targetSwitchStateID, gameObjectID);

SetSwitch pushes the request into the command queue. We record this request ourselves and mark it against the current audio thread frame. At some point the audio thread calls AK::SoundEngine::RenderAudio() and processes the queue. The audio frame counter is incremented. On the next tick (any thread other than the audio thread) we process the list of requests we made and look for anything we haven't yet validated. Any requests recorded against a previous frame can be validated because that frame's command queue has been processed.

Naively I expected to be able to request the currently applied switch state using AK::SoundEngine::GetSwitch:


        // Verify that the switch we requested was actually applied.
        AkSwitchStateID appliedSwitchState{ 0 };
        AK::SoundEngine::Query::GetSwitch(targetSwitchGroupID, gameObjectID, appliedSwitchState);
        if (appliedSwitchState != targetSwitchStateID)
            LOG("The switch was not as expected.");
#endif // !_RELEASE

Unfortunately this fails because "targetSwitchStateID" (the state we recorded to validate against) always matches the switch state returned from AK::SoundEngine::Query::GetSwitch. Instead of returning the currently applied state, which could be either "Default" or the requested state, we are always returned the requested state.

Is there a way to get the the switch state that is actually applied, rather than the (invalid) state we requested?

asked Feb 10, 2022 in General Discussion by Gareth M. (120 points)
edited Feb 23, 2022 by Gareth M.

Please sign-in or register to answer this question.