Post by aikitect on Jun 27, 2024 3:57:58 GMT
Hello I am running into a potential bug with PlaySoundAndWaitUntilFinished. Right now I'm playing a sequence of audio clips using a for loop that calls
The first two times, it seems to work fine, and the sound plays before the code continues to execute. However, for every subsequent sound I play, the code continues to execute BEFORE the sound even plays. I've confirmed this by using the debugger and stepping into PlaySoundAndWaitUntilFinished.
If I set the breakpoint to the if (completedAction != null) line, then it will hit that breakpoint before the sound even starts playing. I'm not sure if the issue is related to the fact that all these clips are playing on one bus with a maximum of one voice, and if the next one plays, it stops the previous one. But even if that's the case, it shouldn't matter because the next clip only plays after the previous clip should finish playing.
yield return StartCoroutine(MasterAudio.PlaySoundAndWaitUntilFinished(soundGroupName));
The first two times, it seems to work fine, and the sound plays before the code continues to execute. However, for every subsequent sound I play, the code continues to execute BEFORE the sound even plays. I've confirmed this by using the debugger and stepping into PlaySoundAndWaitUntilFinished.
public static IEnumerator PlaySoundAndWaitUntilFinished(string sType, float volumePercentage = 1f,
// ReSharper disable once RedundantNameQualifier
float? pitch = null, float delaySoundTime = 0f, string variationName = null, System.Action completedAction = null) {
if (!SceneHasMasterAudio) {
yield break;
}
if (!SoundsReady) {
Debug.LogError("MasterAudio not finished initializing sounds. Cannot play: " + sType);
yield break;
}
var sound = PlaySound(sType, volumePercentage, pitch, delaySoundTime, variationName, null, false, true);
var done = false;
if (sound == null || sound.ActingVariation == null) {
yield break; // sound was "busy" or couldn't play for some reason.
}
sound.ActingVariation.SoundFinished += delegate {
done = true;
};
while (!done) {
yield return EndOfFrameDelay;
}
if (completedAction != null) {
completedAction();
}
If I set the breakpoint to the if (completedAction != null) line, then it will hit that breakpoint before the sound even starts playing. I'm not sure if the issue is related to the fact that all these clips are playing on one bus with a maximum of one voice, and if the next one plays, it stops the previous one. But even if that's the case, it shouldn't matter because the next clip only plays after the previous clip should finish playing.