Is it possible to stop an EventInstance dynamically by calling FMOD_StudioSystem.instance.getEvent("") on a sound that is already playing? I’m having trouble stopping any events with looping regions using EventInstance.stop() method.
I have several events with loop regions that are being played with this method:
public bool Play(string name)
{
EventInstance ei = global_studio.GetEvent("event:/sfx/" + name);
EventDescription ed = null;
ei.getDescription(out ed);
bool isOneShot = true;
ed.isOneshot(out isOneShot);
if (isOneShot)
{
global_studio.PlayOneShot("event:/sfx/" + name, Vector3.zero);
return true;
}
else
{
if (CheckForErrors(ei.start()))
return true;
}
return false;
}
where the event instance is being discarded after it is played. Then the event is attempted to be stopped using this method:
public void Stop(string name, bool allowFadeout = false)
{
EventInstance ei = global_studio.GetEvent("event:/sfx/" + name);
PLAYBACK_STATE playback;
CheckForErrors(ei.getPlaybackState(out playback));
CheckForErrors(ei.stop(STOP_MODE.IMMEDIATE));
Debug.log(name + " stopped");
/*
if (playback == PLAYBACK_STATE.PLAYING || playback == PLAYBACK_STATE.STARTING)
{
if (allowFadeout)
{
CheckForErrors(ei.stop(STOP_MODE.ALLOWFADEOUT));
Debug.Log(name + " stopped");
}
else
{
CheckForErrors(ei.stop(STOP_MODE.IMMEDIATE));
Debug.Log(name + " stopped");
}
}
*/
CheckForErrors(ei.release());
}
The stop method is being called successfully, and ei.stop() and ei.release() pass the ERRCHECK / CheckForErrors function with FMOD.Result.OK, but the sound continues to loop indefinitely in-game. It is as if a new instance of the event has begun playing. When using the block of code that has been commented out in the above method, PLAYBACK_STATE is never found to be PLAYING or STARTING.
Do I have to store a reference to any looping sounds played using the EventInstance.start() method and then retrieve that reference before stopping them?
Thanks in advance.