I have a loopable music track playing and I queue another loopable music track.
I have noticed that when the first loopable music track is added, the logic queues another instance of that first music track, but then when I queue the second music track it’s added after the first queued one (at the tail of the queue).
Is there a way to clear the queue and add the second loopable music track (without touching the source code)?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
On top of that, I have noticed that even if the first loopable music track finishes, the logic never fetches the first track of the
queuedSoundtrackarray and it keeps playing the first loopable music track over and over. Am I doing something wrong here or did I hit a bug? I am using version 1.85.5 in Unity 6.2Here's how I play the first loopable track:
and here's how I queue the second loopable track:
Update I think I have found the culprit here: The
Transition time (s)(akafadeTimeinternally) of my actions is0, meaning that in theSoundtrack.csin ~ line 120, theif (nextSoundtrack.fadeTime > 0f)is never satisfied, and there's noelsestatement there to handle this case.Here's how I fixed it: Given that in this case the
nextSoundtrack.fadeTimeis actually0we can just setaudioSource.loop = false;in theelsestatement so that the logic will hit theif (!IsPlaying ())statement of line 100 once the currently running soundtrack finishes playing and the next (queued) soundtrack will be picked up.I have tested the above change and it works in my case but maybe it introduces regressions.
Are you adding both tracks to the queue at the same time? I'm not clear on the underlying situation.
Track-queueing isn't really intended for looping tracks - since the queuing occurs automatically when the track at the front of the queue ends.
If you want to play a new looping track, have you tried the Crossfade option?
No, I am not adding both tracks to the queue at the same time.
I am playing the first track with looping enabled when the scene starts and then at later point, after a player's action, I am queueing the second tracking with looping enabled.
I don't want to crossfade them, cause they are two versions of the same theme so what I essentially want is when the first track finishes playing, the second track that's already queued to begin playing and loop, so that the transition will be seamless.
I think what you'd want to do in this case, then, is prevent looping from a custom script or Action with:
The change you've made to the Soundtrack script will have unintended side-effects.