Forum rules - please read before posting.

Music Tracks not looping after Load

edited April 2019 in Technical Q&A

Unity 2018.3.12f1
AC 1.67.5

Ok, so... On my first scene I run this action list asset.
https://ibb.co/2kF04j6

To launch the ambience and a loop of music tracks.
All works perfectly, but in a save/load situation.
What happens is that when I load my game after saving it at some random point, the music is not looping anymore. I load, I can hear the music continuing from the point I left it, but when the track is done, is not looping anymore as it does when playing from start. I've no problem with the ambience that instead is looping correctly and I've no problem if playing from Start. The issue appears only after "Load" and both if the music track is the first one (the "PadOnly" from the screenshot above) or one of the shuffled one from the "Shuffle Music" component.
Am I doing something wrong? Or is there something wrong with the "Shuffle Music" action not being "saved"? How can I solve it?

One more thing: is there a way to avoid all the sounds (music, ambience, etc) to play abruptly after Load? Like giving a smooth quick fade in to every sound (like I can do with "Camera:Fade")? (hopefully without assigning a mixer to every sound I've on scene and then set a snapshot).

THANKS A LOT!

Comments

  • The state of the ActionList doesn't get restored - just the state of the currently-running tracks. The first track, "PadOnly", isn't set to loop - which is why it doesn't upon loading.

    You may be able to get around this, however, by checking Resume if played before? and then re-running the ActionList in question upon loading - by way of the OnLoad cutscene field in the Scene Manager.

    is there a way to avoid all the sounds (music, ambience, etc) to play abruptly after Load?

    Using a snapshot would be the best way for this, but if you rely on Audio Mixer Groups in your Settings Manager the assigning is automatic. See the Manual's "Sounds" chapter for more.

  • The "PadOnly" it's because I'd like to start with some sort of intro, before shuffling the Music Storage. Anyway, I can workaround that easily.
    The problem, however, is not solved using the "Resume if played before?" combined with the launching again the ActionList. It's not resuming, but it starts a new track... basically it starts again the shuffling from beginning rather than resuming the track from the "Load" and continue the shuffling. If I set "Loop?" on my Shuffle Music action, then it's looping one track only, not the whole thing (see my previous screenshot).

    For the second point about the non-fading sound when Load. I tried with "Audio Mixer Groups" and snapshots, but it's not working smoothly... Basically I created a snapshot at -80db volume called "No Volume" and one at 0db called "Normal Volume". I then created an "ActionList After Loading" which set the snapshot to "No Volume" in 0 transition time and then to "Normal Volume" with a transition time of 1 second... but it's not working... I also tried to set the snapshot to "No Volume" when my "Loading Menu" is called, and the one to "Normal Volume" alone when "After Loading", but again, is not working smoothly... (and, not sure why, it works almost good on a first attempt, then when I load a saved game after I loaded previously another one, then is not working...)

  • edited April 2019

    The problem, however, is not solved using the "Resume if played before?" combined with the launching again the ActionList.

    At what point did you save the game you're loading - before or after PadOnly has finished? Please test both scenarios by manually clicking "Run now" in the ActionList's Inspector - not via the SavesList "ActionList after loading" field.

    (and, not sure why, it works almost good on a first attempt, then when I load a saved game after I loaded previously another one, then is not working...)

    Please be clear about what's "almost" working vs what's not working. Again, try running the ActionList manually.

    ActionLists do not work inside loading screens.

  • Ok, so, my problems are 2:
    The music not looping and the loading a game having abrupt volumes (not faded).

    For both the issues I've tried both options: Saving a game during the "Pad Only" and saving a game during the "Music Shuffle".
    Concrete example: I save a game during the Shuffle Music, while a track called "Vocoder" is playing half way. If I Load that saved game, the music starts where I left it but it's not looping. If I run again the Action List that shuffle music "On Load", the load starts playing for an instant the "Vocoder" half way, then it starts from zero the loop, shuffling another track (i.e. not resuming the Vocoder, despite "Resume if played before" is checked).

    For the other issue (abrupt sounds on Load), the "almost working" method was the follow:

    • Fade out all the sounds when my "Loading" menu (which turn on on Loading) appears (call a snapshot of the Master Group Mixer to -80db, with transition time 0.5 second).
    • Fade in again all sounds with "After Loading" Action on the Load menu (call a snapshot of the Master Group Mixer to 0db, with transition time 1 second)
      I say "almost good" because there are still some sound glithces (meaning not a totally smooth fade out/fade in of sounds), but overall is acceptable. With the only problem that for some reasons it works only the first time I load the game (for example from the Title Menu). When I'm in game and Load again from the Pause Menu (loading a second time, but the Load menu is the same), all the sounds disappear (like it's not Fading in again), including footsteps and other sfx (not a music related problem).
      This appens no matter which part of the game I'm loading (if on the "Pad Only" or on "Shuffle Music"), scene A or scene B.

    Will dig more into it and provide more details.

  • So far as the shuffling issue goes, this generally sounds as expected - at least so far as the commands you're giving it are. That the shuffle music is set to resume will only have an effect if it selects the music it's already playing - it will still shuffle music when the Action is run. My mention of checking the resume box was in reference to the first Action only.

    What you can try instead is to rely on the OnStopMusic event to play the shuffle music Action whenever music stops.

    First, move your Sound: Shuffle music Action to a separate ActionList asset, and don't have it loop on itself. Remove it from the original ActionList in your screenshot, so that it stops once PadOnly is played.

    Second, place this script as a component in your scene (named OnStopMusicEvent):

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class OnStopMusicEvent : MonoBehaviour
    {
    
        public ActionListAsset assetToRun;
    
        private void OnEnable ()
        {
            EventManager.OnStopMusic += OnStopMusic;
        }
    
        private void OnDisable ()
        {
            EventManager.OnStopMusic -= OnStopMusic;
        }
    
        private void OnStopMusic (float fadeTime)
        {
            if (assetToRun != null)
            {
                assetToRun.Interact ();
            }
        }
    
    }
    

    And assign "assetToRun" as the ActionList with the Music: Shuffle music Action in it. What this will do is run that ActionList whenever music stops - causing it to shuffle again.

    Fade out all the sounds when my "Loading" menu (which turn on on Loading) appears (call a snapshot of the Master Group Mixer to -80db, with transition time 0.5 second).

    AC cannot run ActionLists while loading, but you may get by setting a large Delay before and after (s) value in your Settings Manager's "Scene loading" section.

    As this adds another layer of complexity, however, ignore the Loading menu for the moment and just run the Actions manually via the Inspector during gameplay. Are you able to get the snapshots switching succesfully each time you run them in this way?

  • Dear Chris, I'm back after some days of vacation...
    So, regarding the "OnStopMusic", I can't make it work... Basically I've done as you said (created an empty object on Scene, on which I attached the script you wrote, then assigned the Action for shuffling music). But nothing is happening after the music stop. Am I missing something?

    Regarding the second point (abrupt sounds while loading), can you suggest me a method for setting the snapshots? Because if you say to ignore the Loading menu, how can I fade out the sounds on clicking the "saved list" slot? I guess that for the "Fade In" I can simply write an Action List for the OnLoad of the Scene, but I'm not sure how to fade out the sound the moment the player click on a saved slot... (that's why initially I set to run the action when the Loading menu was appearing).

    Thanks a lot!

  • Am I missing something?

    No, I am. It seems the event only fires if Music is stopped through Actions, and not when they end naturally. I will look further into this.

    can you suggest me a method for setting the snapshots?

    Have you followed my earlier suggestion of running the Actions manually? We first need to determine that the problem is only that you're playing them when Loading.

    In your Load menu's SavesList element, uncheck Load when click on?. The ActionList after loading field will then become ActionList when click, into which you can set the snapshot, wait for it to end, and then load the correct slot manually using the Save: Save or load Action. With an integer parameter, you can map the save slot index automatically from the element, similar to the technique used in this tutorial.

  • It seems the event only fires if Music is stopped through Actions, and not when they end naturally. I will look further into this.

    Oh, I see... Ok, thanks for looking further into it!

    In your Load menu's SavesList element, uncheck Load when click on?. The ActionList after loading field will then become ActionList when click...

    Ok, I will try!

  • UPDATE:
    So I managed to fix the abrupt sounds after loading with the method you suggested and works pretty well! Thanks!

    While I'm still stuck with the "shuffle music" and save/load.
    Have you had time to look further into it? I've no clue on how to make it work...

    Thanks a lot!

  • If you're referring to the OnStopMusic event not firing naturally - yes, this will be addressed in v1.68.

  • If you're referring to the OnStopMusic event not firing naturally - yes, this will be addressed in v1.68.

    Yes, all right, thanks!!! ETA?

  • I'm aiming for this month.

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.