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.

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
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. 

by Mads Maretty S. (Audiokinetic) (39.8k points)
Hi,
And thanks a lot for your answer, but I still can't make it work...
I put the script on my object, put my mute and unmute events in the boxes in inspector view. I have colliders on both my object and my Player...
What am I missing? Do I need to change something in wwise? In the script?
Thanks again for your time.
Hmm, it should definitely work, especially now that both Events are posted using the same functionality.
It's probably something in Wwise then. How did you set up your Wwise Events? Did you both delete the SoundBanks completely (along with the WwiseIDs.h file) and then generate? In your Wwise Event, what's the scope of the two Events?
The two scopes are on global. Basically I have music playing and muted right away on start, and I want to unmute it then mute it with a collide.
What do you mean withe "delete" the soundbank? When I make a change I always save and generate in wwise but why should I delete the bank?
No it should be all fine to just generate them again, but sometimes it maybe be a good idea to delete them completely before generating.
Hmm maybe you should try looking in the Capture Log once entering playmode. Maybe check whether they actually targets the same Wwise object and so on.
All I have in the log is :
Player
UnityEngine.MonoBehaviour:print(Object)
changeColor:OnTriggerEnter(Collider) (at Assets/Assets Perso/changeColor.cs:18)

Player Collided with CUBE
UnityEngine.Debug:Log(Object)
changeColor:OnTriggerEnter(Collider) (at Assets/Assets Perso/changeColor.cs:39)

Wwise(R) SDK Version 2019.1.6 Build 7110.Copyright(c) 2006-2019 Audiokinetic Inc.
UnityEngine.Debug:LogFormat(String, Object[])
AkWwiseInitializationSettings:InitializeSoundEngine() (at Assets/Wwise/Deployment/API/Handwritten/Common/AkWwiseInitializationSettings.cs:288)
AkSoundEngineController:Init(AkInitializer) (at Assets/Wwise/Deployment/Components/AkSoundEngineController.cs:137)
AkInitializer:OnEnable() (at Assets/Wwise/Deployment/Components/AkInitializer.cs:49)

WwiseUnity: Sound engine initialized successfully.
UnityEngine.Debug:Log(Object)
AkWwiseInitializationSettings:InitializeSoundEngine() (at Assets/Wwise/Deployment/API/Handwritten/Common/AkWwiseInitializationSettings.cs:344)
AkSoundEngineController:Init(AkInitializer) (at Assets/Wwise/Deployment/Components/AkSoundEngineController.cs:137)
AkInitializer:OnEnable() (at Assets/Wwise/Deployment/Components/AkInitializer.cs:49)


(my cube also changes color when I collide with it)
Is there something wrong? Or something that should happen that doesn't?
It seems that I also have a lot of this :
Wwise: Insufficient memory in pool: Lower Engine Default. Attempted alloc size: 192000 bytes.
UnityEngine.Debug:LogError(Object)
AkCallbackManager:PostCallbacks() (at Assets/Wwise/Deployment/API/Handwritten/Common/AkCallbackManager.cs:336)
AkSoundEngineController:LateUpdate() (at Assets/Wwise/Deployment/Components/AkSoundEngineController.cs:71)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:303)

Wwise: Plug-in initialization failure: 6946819 (GameObject: Player (UnityEngine.GameObject)) (Instance ID: 19846)
UnityEngine.Debug:LogError(Object)
AkCallbackManager:PostCallbacks() (at Assets/Wwise/Deployment/API/Handwritten/Common/AkCallbackManager.cs:336)
AkSoundEngineController:LateUpdate() (at Assets/Wwise/Deployment/Components/AkSoundEngineController.cs:71)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:303)
Ah sorry, I meant the Profiler's Capture Log.
That shouldn't really be a problem. The Lower Engine Default will be good to get fixed, but as far as I know, it shouldn't cause any problems to muting or unmuting.
Well sorry I'm very new at all of this... Where can I find the capture log? in Wwise? Unity?
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
...