Having issues triggering sound with via MasterAudio

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LewisFTG
Posts: 6
Joined: Sun Apr 15, 2018 5:49 am

Having issues triggering sound with via MasterAudio

Post by LewisFTG »

Hi guys,

I've been trying to use the 'Sequence' field in an individual dialogue node to trigger a piece of background diegetic music.

If I type
MAPlaySound(BackgroundMusic)
I can see MasterAudio is triggering the file but for some reason the volume is defaulting to 0.

I don't understand how to format the syntax for the extra parameters when all I want is to set the volume at 1. Is it this?
MAPlaySound(BackgroundMusic, , 1, , , , )
Sorry for the noob question (not a coder)! Thanks
LewisFTG
Posts: 6
Joined: Sun Apr 15, 2018 5:49 am

Re: Having issues triggering sound with via MasterAudio

Post by LewisFTG »

I figured out why the volume was getting set to 0 (it was in the wrong bus group), but would still appreciate advice on the syntax.
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Having issues triggering sound with via MasterAudio

Post by Tony Li »

Hi,

The syntax may be a little confusing since it's presented in "coder-ese". This is the syntax:

MAPlaySound(soundGroupName, [variationName], [volume], [pitch], [wait], [subject], [follow])

It means the first parameter (soundGroupName) is required. But the rest are optional. If you omit them, they use these default values:
  • variationName: Play a specific variation by name. Default: A random variation is played.
  • volume: Volume percentage (0-1). Default: 1.
  • pitch: Pitch adjustment [-3..3]. Default: No pitch change.
  • wait: Specify true to wait until the sound is done playing. Default: false.
  • subject: GameObject whose position you want the sound to emanate from. Default: Play the sound 2D.
  • follow: Specify true to follow the subject. Default: Don't follow.
You can use this to play a soundGroupName with all the defaults:

Code: Select all

MAPlaySound(BackgroundMusic)
or this to play with volume 1 and the defaults for everything else::

Code: Select all

MAPlaySound(BackgroundMusic,,1)
You need those two commas in there to specify that '1' is the third parameter (volume).
LewisFTG
Posts: 6
Joined: Sun Apr 15, 2018 5:49 am

Re: Having issues triggering sound with via MasterAudio

Post by LewisFTG »

Hi Tony,

apologies for the belated reply. Thanks for your help so far.

I'm now trying to find a way to have the audio fade in at the start, and fade out at the end. Is this possible? I'm trying to see if I can get this to work in the Start node, but so far no joy

Code: Select all

MAPlaySound(ambience_interior_salvage, 0, 0, 1, false, 0, 0);
MAFadeGroup(ambience_interior_salvage,1,5)
Any help appreciated!

Lewis
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Having issues triggering sound with via MasterAudio

Post by nathanj »

Hi,

Edit: My original post (still listed below) didn't address what you're asking. But, I have something of a workaround, which is a little convoluted, but should get the job done.

Make one "Event Sounds" component and give it any unique name, say "Scene1AudioFade", then, from the "Event To Activate" select "Enable". In the "Enable" method choose "Group Control" for "Action Type", "Fade to Volume" for "Group Command", then select the sound you want fade.

Then, from the "Event To Activate" select "Disable" and this time Select "Fade Out All of Sound".

Then disable the Game Object "Scene1AudioFade".

Now, in the dialogue node that plays the sound add an additional sequence "SetActive(Scene1AudioFade, true)"

and for the node that ends the sequence "SetActive(Scene1AudioFade, false)". You'll probably want to put a delay on the Sequence command that stops the audio for the length of the fade as well. Something like "MAStopAllOfSound(soundGroupName)@1"

(Or, rather than using "SetActive" command, you could use "SetEnabled" and just toggle the single component.) This way you could attach a bunch of trigger components to one game object and keep your scene a little neater!)

Image

Or, much more simply, could you just select "Use Custom Fading" from the "Master Audio Groud" component?

Or is this sound used for multiple events and sometimes its faded and other times not?

Image


Nathan
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Having issues triggering sound with via MasterAudio

Post by Tony Li »

Hi,

Nathan has a good point. You may prefer to set up the fade in Master Audio itself.

If you want to set it up in a dialogue entry node, I'll describe it below. The MAFadeGroup() sequencer command takes three parameters:
  • Sound group name
  • Target volume
  • Fade time
If you want to fade out the sound group "ambience_interior_salvage" to volume 0 (silence) over a duration of 5 seconds, use this command:

Code: Select all

MAFadeGroup(ambience_interior_salvage, 0, 5)
However, let's say you want to fade out to volume 0 (silence) over a duration of 1 second, starting at the 5-second mark. Then use this command instead:

Code: Select all

MAFadeGroup(ambience_interior_salvage, 0, 1)@5
The "@5" part tells the command to start at the sequence's 5-second mark.

The whole sequence would be:

Code: Select all

MAPlaySound(ambience_interior_salvage, 0, 0, 1, false, 0, 0);
MAFadeGroup(ambience_interior_salvage,0,1)@5

To test this in the Dialogue System's regular demo scene, I used these steps:

1. Copied the MasterAudio GameObjects from the Dialogue System's Master Audio Example scene into DemoScene1.

2. Edited the Demo Database's Private Hart conversation. Set the <START> node's Sequence to:

Code: Select all

MAPlaySound(King,King,1);
MAFadeGroup(King,0,1)@0.5
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Having issues triggering sound with via MasterAudio

Post by nathanj »

:lol: can't believe i didn't notice MAFadeGroup

you need a facepalm emoji
LewisFTG
Posts: 6
Joined: Sun Apr 15, 2018 5:49 am

Re: Having issues triggering sound with via MasterAudio

Post by LewisFTG »

Hey guys! Appreciate your help!

Looks like this suggestions will probably be very useful!

Many thanks!
Post Reply