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.

Mute and unmute with the same trigger

0 votes
Hi,

Here is my issue : I’m trying to unmute a sound when I collide with an object in unity, and then mute it back when I collide with the same object. When I put the two events in the object only one event works. If the sound is playing muted it unmutes when I collide, but doesn’t mute back....

Is there a way to do this?

 

Thanks a lot
asked Dec 8, 2019 in General Discussion by Clément B. (100 points)

1 Answer

0 votes

Hey Clement, 

One of the most solid solutions, would probably be to make a script for this. I would use Wwise Types, and then a bool to swap between when it's supposed to be muted or not. 

Here's an example that you can copy / paste into Unity: 

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

public class MuteAndUnmute : MonoBehaviour
{
    public AK.Wwise.Event Mute;
    public AK.Wwise.Event Unmute;

    // True or False condition. 
    public bool muteCondition = true;

    private void OnCollisionEnter(Collision collision)
    {
        // swaps the true/false condition...
        muteCondition = !muteCondition;

        // if "muteCondition" is true
        if (muteCondition)
        {
            // post the event assigned in Mute
            Mute.Post(gameObject);
        }
        else // if "muteCondition" is not true 
        {
            // post the event assigned in Unmute
            Unmute.Post(gameObject);
        }
    }
}

This basically posts either the Mute or Unmute Event based on a boolean, which can only be True or False. 
So because I set the muteCondition to True, it will first become false (muteCondition = !muteCondition;) and then the if statement will post the Unmute Event. 

Hope this get you started. Otherwise, the Wwise-301 course might with the introduction to making scripts, so you can create all these kind of custom behaviours in the future. 

answered Dec 9, 2019 by Mads Maretty S. (Audiokinetic) (38,720 points)
No problem! In Wwise. Go to layouts > Profiler and look in the Capture Log. You can even filter out the calls, by selecting the objects (the ones you targeted in the Wwise Event) in the Filter > Wwise Objects. Hope it helps!
Ok so the interaction with the cube doesn't seem to work.
Maybe I'm doing something wrong at the begining : I play bunch of layers at start and mute them at the same time (with two events "play all" and "mute all"). During the game, with triggers, I unmute them one by one, then at some point mute them again with one event. So after this point I want to unmute only one of them by colliding.
So in the capture log, for this one particular layer, I can see the first Unmute, then the mute, but nothing when I collide with the cube.

Timestamp    Type    Description    Wwise Object Name    Game Object Name

 0:05:12.917    Event    Event Triggered    UnMute_Farfisa_01    Trigger_Colline (1)
 0:05:12.874    Event    Event Triggered    UnMute_Farfisa_01    Trigger_Colline (1)
 0:06:22.997    Event    Event Triggered    Mute_Fade_Music_Colline    Trigger_Colline (4)
 0:06:23.018    Event    Event Triggered    Mute_Fade_Music_Colline    Trigger_Colline (4)


And I don't know if this is normal but as you can see each time I have 2 lines for each trigger.
Sorry my response took a long time to be validate.
And I learned something, when you change an ak event in unity while you're in play mode, it changes EVERY ak event in your project....
So after that I cried a little, then I redid everything, and then I'm back still with the same issue. Any idea?
Thanks
"And I learned something, when you change an ak event in unity while you're in play mode, it changes EVERY ak event in your project...." - That should definitely not happen! Unless you've marked all of them.

Alright, so I just quickly replicated what you did in Unit and it seems I have a similar problem! Can you try muting and unmuting everything on a game object basis?

If that doesn't work, instead of muting with a mute event, you could try to make an RTPC and then hook it up to the Voice Volume of the audio object you're trying to mute. In such a case, you just set the RTPC from the same Events you used earlier.

Here's a few screenshots of how I made it work with RTPCs. Hopefully I understood your setup correctly?

https://drive.google.com/open?id=1_D87gDh7r3_4DTp1REcYzcAD6LNeGJeX

Let me know if that works!
Hi Mads,
I finally managed to do it!
The problem was that both my objects (Player and Cube) had a rigidbody and both used kinematic. I think that for OnCollisionEnter to work, one of them has to be non kinematic. And yes it actually works like that. Problem is my cube is flying away as soon as I touch it.
So instead I kept it kinematic but used OnTriggerEnter (with a box collider on trigger on my player).
And it works perfectly, I just had to modify a bit your first script. Here is my final one :

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

public class MuteAndUnmute : MonoBehaviour
{
    public AK.Wwise.Event Mute;
    public AK.Wwise.Event Unmute;

    // True or False condition.
    public bool muteCondition = true;

    void OnTriggerEnter(Collider other)
    {
        if (other.name == "Player")
        {
            // swaps the true/false condition...
            muteCondition = !muteCondition;

            // if "muteCondition" is true
            if (muteCondition)
            {
                // post the event assigned in Mute
                Unmute.Post(gameObject);
            }
            else // if "muteCondition" is not true
            {
                // post the event assigned in Unmute
                Mute.Post(gameObject);
            }
        }
    }
}

But I'll give a try with RTPC, seems to be a nice way too.

Anyway thank you so much for taking time to help me, you've been a great help and I learned a lot about scripting thanks to you!
Thanks again and Have a nice day

Clement
...