I have a question regarding music integration. I’m hoping someone can help.
In this game I’m working on we have music that is triggered in the main level, but when a player enters a building that music stops until the player exits the building.
Upon exiting the building the music comes back on but always starts at the beginning of the piece.
Is it possible in F-MOD to set it up so that when exiting a building the music resumes from where it left off before the player entered the building?
It sounds like you might be calling Play on the sound to resume it after the pause.
Calling play on an event will start it from the beginning, you need to use setPaused(false) to resume a paused event.
Thank you Cameron. Is this something on the code side? So I need to set my event up in F-Mod Studio any differently? I just have an event set to looping, nothing fancy.
I’m trying to do the same thing, and followed the suggestion laid out here, but I’m getting a console error:
‘EventInstance’ does not contain a definition for ‘EventInstance’ and no accessible extension method ‘EventInstance’ accepting a first argument of type ‘EventInstance’ could be found (are you missing a using directive or an assembly reference?
Here’s my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;
public class MusicManager : MonoBehaviour
{
public FMOD.Studio.EventInstance levelMusic;
public GameObject pauseMenuOB;
private bool pauseMenuOn;
void Awake()
{
PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
pauseMenuOn = pauseMenu.pauseMenuOn;
levelMusic = FMODUnity.RuntimeManager.CreateInstance("event:/Music/Chapter1/1_1_Lobby");
levelMusic.start();
}
void Update()
{
PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
pauseMenuOn = pauseMenu.pauseMenuOn;
if (pauseMenuOn) levelMusic.EventInstance.setPaused(true);
else if (!pauseMenuOn) levelMusic.EventInstance.setPaused(false);
}
}
void Update()
{
PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
pauseMenuOn = pauseMenu.pauseMenuOn;
if (pauseMenuOn) EventInstance.setPaused(true);
else if (!pauseMenuOn) EventInstance.setPaused(false);
}
But now, I’m getting an Object Reference error: “An object reference is required for the non-static field, method, or property ‘EventInstance.setPaused(bool)’”