Forum rules - please read before posting.

Change music volume from Options of combined output of two tracks with variable relative volume

Right now, my game has an Object that plays two music audio tracks simultaneously from runtime except one of them at volume zero initally. It has a script that makes that track fade in and fade out when certain actions are performed.
I would like to allow the player to control the music volume from the Options menu, but I'm encountering difficulties in my attempts to do this:
1) I can't just add the Sound script component to the object and set it to 'Music' because for some reason then when the player changes the volume slider that causes the two tracks to desync.
2) I can't set both as Music tracks to play On Start, and then control the volume of the second one with Actions. For one thing, setting one of track's relative volume to zero will also nullify the other one, I'm guessing due to multiplication.
3) Maybe I could get it to work if I set them as different types (one plays as music, the other as ambience, for example) but have one slider change the volume of both simultaneously in Options (I wouldn't need to use Ambience for anything else anyway)
Any recommendations?
Here's a copy of the code I'm using to fade in and out the second music track. I call the function ChangeMusic from the Actionlist. I'm guessing I might have to do away with the code and perform the same function in a different way?

Comments

  • edited February 2022

    Audio Mixer Groups should be able to help here. When your game opts to make use of them, Option sliders affect these instead of individual Sound components - meaning you can attach them to custom AudioSource components, or create child dependencies for greater control.

    A tutorial on working with mixers can be found here.

    Once set up, you can then assign the Music mixer to your custom object to have it control its volume from the Options menu.

    Alternatively, your idea of using Ambience and Music together, is also possible. Both "Storage windows" for Music and Ambience tracks can be assigned a Mixer Group asset to override the default. If you assigned your Music group to the Ambience storage window, then both Ambience and Music volume will be controlled by the same group - allowing you to rely on AC's built-in Actions rather than a custom script. This also gives you the advantage of their states being recorded by the save-game system.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.