top of page

Query Wwise with Waapi and Waql

Updated: Aug 26, 2023

There are three ways to trigger queries from code. With two of them you are also able to create the queries on the fly.

  1. Creating Waql queries and trigger them

  2. creating Waapi queries and trigger them

  3. Triggering queries that were created in Wwise

To better follow whats going on, here is the official Wwise Documentation.


Setting up the connection

First we need to establish a connection to Wwise.

AK.Wwise.Waapi.JsonClient client = new AK.Wwise.Waapi.JsonClient();
await client.Connect();

Using Waql to get all Wwise queries

In order to retrieve all Wwise queries we can use waql.

The command would be the following. You can press control+shift+f in wwise to open the list view and try it out.

$ where type="Query"

To trigger that in code we need to wrap our command in a json format.

JObject argument = new JObject(
    new JProperty("waql", "$ where type="Query"")
);
//information we want to get returned
JObject options = new JObject(
    new JProperty("return",
        new string[] { "name", "id", "path", "type", "workunit"}));
        
JObject queryResults = await client.Call(ak.wwise.core.@object.get, argument, options);

Trigger a Wwise query

We could display all of the retrieved queries in the section above in some Gui-Application and store the query id.

If the query doesnt find any objects the call function will throw an exception. For that reason we need to wrap it in a try catch.

try
{
    JObject argument = new JObject(
        new JProperty("from", 
            new JObject(
                new JProperty("query", 
                    new JArray(new string[] { id })))));
                  
    //information we want to get returned  
    var options = new JObject(
        new JProperty("return",
            new string[] { "name", "id", "path", "type", "workunit"}));
    
    JObject queryResults = await client.Call(ak.wwise.core.@object.get, argument, options);
}
catch (AK.Wwise.Waapi.Wamp.ErrorException e)
{
    //handle the case that you dont get any query results.
}

Creating a Query using Waapi

Wrapping your head around creating query calls with waapi is a bit more complicated, since you need to build them with the json structure. But once done its just as simple as the rest.

In this one we are getting all the children in a path. A path can be somethin like "\Actor-Mixer Hierarchy".

string path = "\Actor-Mixer Hierarchy";
JObject argument = new JObject(
    new JProperty("from",
        new JObject(
            new JProperty("path",
                new JArray(new string[] { path })))),
    new JProperty("transform",
        new JArray(
            new JObject(new JProperty("select",
                new JArray(new string[] { "children" })))))
);

JObject options = new JObject(
    new JProperty("return",
        new string[] { "name", "id", "path", "type"}));

JObject queryResults = await client.Call(ak.wwise.core.@object.get, argument, options); 

There are three building blocks that you can use.

new JArray()
new JObject()
new JProperty()

You will need to encapsulate an argument which is for example "from", "path" or "transform" into a JProperty. The second argument of the JProperty is either a JObject or JArray depending on your argument. You can look that up for the ak.wwise.core.@object.get command here.



The result

Retrieving the desired variables from the results work fairly easy.

Like that we would get the name from all items the query returned.

//queryResults["return"][your option of choice]
foreach(JToken res in queryResults["return"])
{
    string name = res["name"];
}


Comentarios


bottom of page