How to stop the AudioComponent once it's played through all data in a USoundWaveProcedural?

Hi everyone,

Context:

I have audio being streamed to my Unreal Engine 5 client via WebSocket server. To play the received audio, I use USoundWaveProcedural and queue it via the QueueAudio() function.

The audio successfully plays in an AudioComponent, however, the AudioComponent never stops playing and doesn’t call OnAudioFinished.

Digging through the source code, I’ve learned that when the USoundWaveProecedural no longer has any bytes available (underflow) in its GeneratePCMData() function, it will continue to generate 0s (silence) to be played by Audio Component.

I’ve tried stopping this by creating my own custom subclass of USoundWaveProcedural, which after receiving an “audio stream stop” flag from the WebSocket server, causes the USoundWaveProcedural to no longer pad with 0s on underflow, however, while this does stop the AudioComponent, for some reason it fails to play all the audio.

Question:

Given a USoundWaveProcedural, how can I have it stop correctly once all queued data has been played?

What I ended up doing was deleting my custom subclass of USoundWaveProcedural and instead, attached a delegate to the AudioComponent’s OnAudioMultiEnevelopeValue and stopping the AudioComponent after it detects 500ms of silence (basically a value lower than 0.001) and that seems to work