Forum rules - please read before posting.

Layered Music tracks and 'Sound type: Music'

Hey, I'm currently working on music related things and have a question regard layered tracks:

What is the best way to go about handling music tracks that have multiple layers that are designed to fade in/out as needed?

For example you might have a drum beat playing as background music with a guitar part that fades in based on what is happening in the scene. The guitar part would need to be perfectly in sync with the background music.

The 'Sound: play music' action does not seem up to the task as it is designed to handle just one music track, I have tried having multiple audio sources for each layer that are set to 'play across scenes' but as soon as I set these to 'Sound type: Music' only one is able to play.

It seems this could be achieved using a different sound type (SFX or speech) but I would like these tracks to have their volume controlled by the music vol slider in my options menu.

Any advice would be appreciated, the main aspects I need are:

music can be played across scenes
music resumes from previous timecode when new scene is loaded
music is linked to music volume slider in options menu

I can control the audio source's volume myself to handle the fading of tracks, given that AC is able to play sounds when their volume is set to 0.

Comments

  • edited November 2023

    Setting 'Sound type: Other' and then manually assigning the Audio Source output to the Music mixer group seems to work :smile:

    I'm not sure what would be the best approach for managing this? As the game object is not destroyed between scenes I assume I would need to have them present in the first scene of the game then (I guess) reference them with an actionlist asset that can be called whenever I need to play/stop audio.

    That seems like it could introduce issues, from what I gather the audio sources need to be playing an audio file to survive the scene change.

    If I put them in every scene the previous scene's music stops when loading a new scene (presumably because there are now two instances of each audio source, one having survived the scene change).

    I feel I may have bitten off more than I can chew heh

  • edited November 2023

    I use timeline to do this! I set up (for example) 3 audio sources, each linked to a different mixer group, and I assign each audio track in the timeline to one of those audio sources. The timeline is used to make sure the tracks are always in sync.

    I've found that the best way to keep things persistent throughout the game is to add them to the player prefab, as long as you don't use character switching to have multiple characters (if you do use multiple characters, you'd need to write your own script to spawn the objects when the game is first started and to add them to DontDestroyOnLoad).

    In the case music, this works perfectly unless you need the music to be 3d (i.e. if the music is supposed to come from a specific location in the scene).

  • edited November 2023

    Yes, mixer groups sounds like the way to go. If you create "child" groups that derive from Music, you can control their volume independently while still having them be affected by the main "Music" volume in the Options data.

    Timeline's a smart approach to the syncing up. The alternative would be to rely on script. To get the current time samples of the "main" Music (the one played via Sound: Play music) use:

    AC.KickStarter.stateHandler.GetMusicEngine ().audioSource.timeSamples
    

    The 'Sound: play music' action does not seem up to the task as it is designed to handle just one music track

    While this is true, you can still have other Sound objects of the type "Music" in your scene playing independently - provided you've unchecking Auto-end all Music when play? in the Music Storage window. IIRC this is a relatively new feature, so you'll need to be up-to-date on your AC version.

    if you do use multiple characters, you'd need to write your own script to spawn the objects when the game is first started and to add them to DontDestroyOnLoad

    For convenience, a small script that moves the attached object to DontDestroyOnLoad will be included in the next release. The "non-scripting" way to approach this would be to attach the new Survive scene changes component to your prefab, and then use the Object: Add or remove Action to spawn it in as part of your Settings Manager's ActionList on start game asset.

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.