Music event carries on playing dispite stopping it by code

Hi!

We’ve just release Space Routine on Humble Bundle Originals and when one gameplay review came online we noticed a strange (and a bit humilliating) bug we haven’t encountered in these last couple of month of testing.
We organized the fmod to have one event with like 10 nested events, each one with one track of music. So all music is managed and played from one single event, where 8 are single tracks in streaming and 2 of them are preloaded, adaptative, multitrack ones. They all have a prefader send to diferent faders so that we change the music vía a parameter that activates snapshots that lowers all the faders but leaves only the selected track’s fader up. This was done this way so that the music crossfades but is always starting at a different time to give the idea that despite not being at a certain spot of the map, the action in that place still carries on. Also, to avoid listening to the same first seconds of each track each time you enter a space station.
So, the bug in question is that in this review: https://www.youtube.com/watch?v=H5m4gecPw8o&t=3m49s you can see in the minute 3:49 that even when pressing “play” the loading screen still has the menu’s music, and it carries on during the game ON TOP of the games music. Like there are two music event instances at the same time, one with the parameter set on “menu music” and the other one working correctly (changing according to the station you’re in). The unity code stops the music event when this “play” button is pressed and also it changes unity scene, so the music event should not only stop but also be destroyed and loaded again in the game’s scene. But still this happened! This is werid and we have no clue on what the problem could be. It would be a bummer if more reviews came along with this so we’re traying to fix it. Any ideas on what could be happening?

The unity code when pressing play:

public void PlayGame()
    {
        if (!started)
        {
            SoundManager.instance.Stop(Music, true);
            SoundManager.instance.Play(PlayBtn);
            started = true;
            //PlayerPrefs.SetInt("Random", 0);
            //PlayerPrefs.Save();
            //SceneManager.LoadScene(1);
        }
    }

And the function it activates is this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;

public class SoundManager : MonoBehaviour
{
    // Start is called before the first frame update
    public static SoundManager instance = null;
   
    void Awake() //Create Singleton
    {
        if (instance == null) { instance = this; }
        else if (instance != this)
            Destroy(gameObject);
        //DontDestroyOnLoad(gameObject);
    }

    void Start()
    {

    }

    
    public void ChangeParameter(EventInstance Event, string parameterName, int parameterValue)
    {
       
        Event.setParameterByName(parameterName, parameterValue);
       
    }
   
    public void Play(EventInstance Event)
    {
        Event.start();
    }
 
    public void Play(EventInstance Event, Transform pos, Rigidbody rig)
    {
        RuntimeManager.AttachInstanceToGameObject(Event, pos, rig);
        Event.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(pos));
        Event.start();
    }
  
    public bool EventHasThisParameterValue(EventInstance Event, string parameter, int value)
    {
        bool hasValue = false;
        float paramValue;
        Event.getParameterByName(parameter,out paramValue);
        if (paramValue == value)
        {
            hasValue = true;
        }

        return hasValue;
    }

    public float ParameterValue(EventInstance Event, string parameter)
    {
        float value = 0f;
        Event.getParameterByName(parameter, out value);
        return value;
    }

    public bool isEventPlaying(EventInstance Event)
    {
        bool isPlaying = false;
        PLAYBACK_STATE state;
        Event.getPlaybackState(out state);
        if (state == FMOD.Studio.PLAYBACK_STATE.PLAYING)
        {
            isPlaying = true;
        }

        return isPlaying;
    }

    public void Stop(EventInstance Event,bool Fade)
    {
        if(Fade)
        {
            Event.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
        }
        else
        {
            Event.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);

        }
        
    }
}

And this is a screen of the FMOD structure we use for crossfading and managing the different tracks of the single music event:

Thanks!

This sounds weird, the code looks fine to me. You can’t reproduce it, right? What I would do in your situation is to check what the stop method returns, it should return FMOD.RESULT.OK:

    if (Fade)
    {
        FMOD.RESULT result;
        result = Event.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

        #if UNITY_EDITOR
        Debug.Log(result);

        if (result != FMOD.RESULT.OK)
        {
            Debug.Break();
        }
        #endif
    }

Then maybe find a way to automate the clicking on the play button process, restarting the menu scene and doing it again, so you can run the code a lot of times and check if there is anything going wrong, taking a look at the profiler at the same time. Not the best programmer, but that would be my first approach to this problem.

Where are you creating the Music and PlayBtn instances by the way?

In case I couldn’t find any solution, I would try to stop the music bus before starting the PlayBtn instance:

    var musicBus = FMODUnity.RuntimeManager.GetBus("bus:/Music");
    musicBus.stopAllEvents(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);

As @alexzzen mentioned, checking the result of the stop call will tell you if it failed for any reason.

Is it possible that the Event Instance has been cleared or overwritten before stop has been called?