How to have different BGM on different scenes while using FMOD?

Viewed 19

I'm quite a new game programmer and the studio/company I'm working in need to implement a couple of BGMs (around 5) into different scenes (around 10, with 5 of them having high priority) in the game project.

Problem is, I don't understand FMOD codes that much and doesn't know how to make a script that would change the BGM in different scenes. I tried making a rough script using PlayOneShot, but as expected the BGM wouldn't stop playing when I switched scene.

I really need help with this problem, and I don't have a script for it yet.

1 Answers

Instead of PlayOneShot, start BGMs with instances and when you need to stop them, stop them with instance;

    public FMODService FMODService { get; set; }

    private EventInstance _instance;

    public void StartBGM()
    {
        _instance = FMODService.GetInstance("event:/the_BGM");
        _instance.start();
    }

    //Your scene callback when it loads etc.
    public void OnLevelChange()
    {
        _instance.stop(STOP_MODE.ALLOWFADEOUT);
    }

}
Related