Community Q&A

Where Wwise users help each other out!

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

Unity - Want to fade background music when player approaches an AKAmbient object, and then fade background music back in

0 votes
WWise Ver: 2019.2.5

Unity Ver: 2019.4.8f1

Hello,

I have a Unity scene which plays some background music, and has an object in it which plays some spatial music via the AkAmbient component.

I want to fade the background music out as the player gets close to the object, and then fade the background music back in when they move away from it. My goal therefore is to have it so both pieces of music can be heard without them clashing together.

I've tried auto-ducking by using buses. This doesnt work because the spatial audio is set to 'Trigger On: Start' so as soon as the scene starts the background music ducks out before the player is close to the object. I've also tried changing to 'Trigger On: AkTriggerEnter' which works better - but then the background music never resumes because I assume once triggered the AkAmbient bus just stays active.

What can I do to get the behaviour I want?
asked Nov 3, 2020 in General Discussion by Pete B. (220 points)

1 Answer

+1 vote
 
Best answer

Hey Pete, 

There's quite a few ways to do this, but I would probably use busses with some adjustments. 

I noticed you write... 
"as soon as the scene starts the background music ducks out before the player is close to the object."
- Do you have attenuation on the non-background music? Ducking should definitely not duck, unless something is actually playing through it. Alternatively, you could try attaching a Wwise Meter to the non-background music bus, and then connect the RTPC from it, to the volume of the background music. 

Another less "volume-based" solution could also be to set an RTPC based on how close you are to the non-background music and map it to the volume of the background music bus. This should work quite well, as the RTPC influence will only subtract volume from the background music's audio bus, and so you can still have like a volume control RTPC on it as well. 
- You can do that by creating a new script, and in your Update() function, set the RTPC to the Vector3.Distance(transform.position, playertransform.position). 

If you want to see how this could be implemented, then for the Audio Bus ducking solution you can check out the arcade machine in WAG, that does exactly the same for the main music when it plays. For the method of setting an RTPC in Update, there's a section in Wwise 301 that describes more about that. 

Let me know if this helps!

answered Nov 4, 2020 by Mads Maretty S. (Audiokinetic) (9,170 points)
selected Nov 6, 2020 by Pete B.
Hey there. Thanks, I'll give those ideas a bit of research.

Quick note though - in WAG the arcade machine doesn't do anything for me. I get an interact prompt, which does nothing, and certainly no sound is heard.
"then for the Audio Bus ducking solution you can check out the arcade machine in WAG, that does exactly the same for the main music when it play"

Can you screen shot where in WWise the ducking is setup? I'm having a look at the project in WWise but I'm feeling quite lost.
In the end I went for the script option and setting the RTPC that way. I would love to know the other ways of doing this by using audio buses, but I was unable to figure it out.

In this case, the WAM wasn't helpful. The example of the arcade machine simply doesn't work for me (it never makes any sound when playing the game)and also I noticed the setup of the arcade machine is on interact which involves start and stop events. This is different to my scenario; I have an AKAmbient component which simply has a 'Trigger On: Start' setting. There is no notion of stopping it.
...