First things first, using Unity 2021.3.20f1 with FMOD 2.02.13 as my audio manager.
I am working on setting up my game’s main menu, and I want to have a music transition after the player has selected to either play or quit the game.
In FMOD, I established a continuous parameter named CloseMenu with a range of 0 to 1 (0 being the normal state of the menu, and 1 being the transition). I setup the tracks with a loop for the normal state, and a one-shot clip for the transition. Added a destination marker named “CloseMenu” at the start of the transition clip, and a transition region (quantized to the quarter note) pointed to this marker, and set the transition conditions to the CloseMenu parameter range 1-1. (Screenshot 1 attached shows all of this). Tested it out within FMOD, and the transition works as it should.
Over to Unity, I have a Game Object called “containsScript” which is what I have my manageMenu script as well as the FMOD Studio Event Emitter attached to (Screenshot 2).
In the ManageMenu script, I set a public integer “endMusicTrigger” which is intended to be the trigger for the CloseMenu parameter in FMOD. I have the code set so that when the player clicks either the Start Game [loadMainGame()] or Exit Game [button_exit()] buttons, the code sets the endMusicTrigger integer from 0 to 1. And then I use code “menuMusic.setParameterByName(“CloseMenu”, endMusicTrigger);” to change the parameter within FMOD and trigger the transition. (Here’s the full code for the menu):
[code=CSharp]using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.SceneManagement;
public class manageMenu : MonoBehaviour
{
public FMOD.Studio.EventInstance menuMusic;
public Animator FadeAni;
private float timer;
private bool timerStarted;
public float delayFadeTime;
private bool startNewGame;
private bool exitGame;
public int endMusicTrigger;
void Start()
{
timer = 0.0f;
timerStarted = false;
delayFadeTime = 4.0f;
startNewGame = false;
exitGame = false;
endMusicTrigger = 0;
menuMusic = FMODUnity.RuntimeManager.CreateInstance("event:/Music/Menus/MainMenu");
menuMusic.setParameterByName("CloseMenu", endMusicTrigger);
}
void Update()
{
if (timerStarted && startNewGame)
{
timer += Time.deltaTime;
if (timer >= delayFadeTime)
{
timerStarted = false;
SceneManager.LoadScene("Chapter1");
}
}
if (timerStarted && exitGame)
{
timer += Time.deltaTime;
if (timer >= delayFadeTime)
{
timerStarted = false;
Application.Quit();
}
}
}
public void loadMainGame()
{
FadeAni.SetBool("fadeOut", true);
startNewGame = true;
timerStarted = true;
endMusicTrigger = 1;
menuMusic.setParameterByName("CloseMenu", endMusicTrigger);
print("Load Main Game");
}
public void button_exit()
{
FadeAni.SetBool("fadeOut", true);
exitGame = true;
timerStarted = true;
endMusicTrigger = 1;
menuMusic.setParameterByName("CloseMenu", endMusicTrigger);
print("Exit Game");
}
}
[/code]
In theory, I believe I’ve set everything up correctly, but for some reason when I click on the the Play Game button, the endMusicTrigger integer successfully changes to 1, but the CloseMenu parameter remains at 0 (Screenshot 3).
Not getting any console errors to cue me into what I’m missing, and everything I’ve read up on says that this should be effective, so hoping someone may have a clue as to what I’ve done wrong (I’m new to Unity, FMOD, and scripting, and self-taught, so I’m sure it’s probably something stupid I just overlooked, lol).