I have two scenes ( A and B ) where I need to play the same ambience track (a clock ticking) but with a different volume in every scene, so that the game gives the impression that the player is closer to the clock.
Currently I am using two different ambience tracks in the Ambience Storage that contain the same clip with a different 'relative volume', one for far away (scene A: relative volume: 0.5) and one for closer (scene B: relative volume: 1). I want the ambience track to continue playing when the game transitions from scene A to B and vice versa, so I have added a crossfade action during the OnStart ActionList of every scene. This though does not line up perfectly every time and the clock sound can be heard twice while the crossfade is performed.
Is there a way to affect the ambience track volume via an ActionList action or programmatically?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Yes - it'd be better to rely on a single track and control its volume, to avoid having to sync two separate tracks together.
You can programatically control the **Relative volume* slider for the track as it appears in the Ambience Storage window. This'll take the form of:
Where "X" is the ID value of the track.
You can get this API reference for any Editor field by right-clicking the label - a tutorial on this, and updating it through script can be found here.
Thanks for the quick reply Chris!
Changing the value of the
relativeVolume
property on the fly doesn't seem to affect the actual volume of the track that's being played though, unless I am doing something wrong.I was able to make this work via Reflection (by accessing the underlying
SetRelativeVolume()
method of theSoundtrack
class), but it feels kinda hacky to me:and then calling
KickStarter.stateHandler.GetAmbienceEngine ().SetRelativeVolume(relativeVolume);
Ah, my mistake - the track's relativeVolume property is only applied at the point the track begins playback.
The relativeVolume in the Soundtrack class is public, however. Just call SetMaxVolume afterwards to apply changes to it:
Thanks Chris! That's definitely a cleaner approach. I will use that instead on the new custom Action I have created to control the relative volume of the ambience track from an ActionList.
Have a great weekend!