Hello!
I have a weird problem… There is this 2D looped event that does not stops playing when I start it in a specific unity scene. There is nothing special about the event i’m leaving here a print:
I have a sound manager singleton with a list of event instances I load when the game starts. And so far it has worked perfectly. (I barely know how to describe it because it’s so simple, I doubt very much that it’s a scripting problem)
Anyways, here it is the sound manager script (it inherits from a singleton base class)
public class SoundControl : BaseService<SoundControl>
{
[FMODUnity.EventRef, Space(20), SerializeField]
private string[] fmodEvents;
private readonly List<FMOD.Studio.EventInstance> instances = new List<FMOD.Studio.EventInstance>();
public bool InstancesLoaded { get; private set; }
private void Awake()
{
SetupService(this); //this is just singleton initialization
InstancesLoaded = false;
StartCoroutine(LoadInstancesList());
}
private IEnumerator LoadInstancesList()
{
for(int i = 0; i < fmodEvents.Length; i++)
{
instances.Add(FMODUnity.RuntimeManager.CreateInstance(fmodEvents[i]));
yield return null;
}
InstancesLoaded = true;
}
public bool IsPlaying(FMOD.Studio.EventInstance instance)
{
if (instance.isValid())
{
instance.getPlaybackState(out FMOD.Studio.PLAYBACK_STATE state);
return state != FMOD.Studio.PLAYBACK_STATE.STOPPED;
}
return false;
}
public int GetInstancesCount() => instances.Count;
public void PlayInstance(int index)
{
if (InstancesLoaded)
{
Debug.Log(instances[index].start()); //returns OK
}
else
StartCoroutine(Delay(true, index));
}
public void StopInstance(int index)
{
if (InstancesLoaded)
{
if (IsPlaying(instances[index])) //returns true
{
Debug.Log(instances[index].stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT)); //returns OK
if (IsPlaying(instances[index])) //returns true
{
//I tried to release the instance to see if it stops but...
Debug.Log(instances[index].release()); //returns OK
Debug.Log(instances[index].stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT)); //returns OK
}
//it doesn't
if (IsPlaying(instances[index])) //returns true
Debug.Log("why? why isn't that possible?");
}
}
else
StartCoroutine(Delay(false, index));
}
IEnumerator Delay(bool start, int index)
{
yield return new WaitUntil(() => InstancesLoaded);
if (start)
Debug.Log(instances[index].start()); //returns OK
else if (IsPlaying(instances[index])) //returns true
{
Debug.Log(instances[index].stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT)); //returns OK
if (IsPlaying(instances[index])) //returns true
{
//I tried to release the instance to see if it stops but...
Debug.Log(instances[index].release()); //returns OK
Debug.Log(instances[index].stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT)); //returns OK
}
// it doesn't
if (IsPlaying(instances[index])) //returns true
Debug.Log("why? why isn't that possible?");
}
}
To play and stop the event instance I want, I just do the following and the methods are called normally:
SoundControl.Instance.PlayInstance(6);
SoundControl.Instance.StopInstance(6);
Anyways, the problem is that this whole thing work fine, even for the event in question, if I call it in another scene it stops correctly. But in this specific scene it doesn’t work. I can start it, but can’t stop it.
I don’t know if I missed any details, that’s why I’m bringing this question here…
Any help?
I’m using fmod version 2.01.07 and fmod unity integration version 2.01.07.
Thanks in advance