Stop audio overlapping?

I have a few close triggers in a level that if the player hits, play voice over. But if the player hits one after another, the audio overlaps. I put this code together in the level blueprint to delay the second audio, but the more triggers around the area, the more branches it needs.

Is there a cleaner way to achieve this? I tried the code underneath but it doesn’t work.

Do I understand your requirements correctly.

  1. Player hits triggerbox 1 - play sound
  2. Player hits triggerbox 2 while sound above is still playing.
  3. Wait for sound from triggerbox 1 to stop then after .2 seconds start triggerbox 2 sound.

There are N number of possible triggerboxes.

Let me know and I’ll have a think about a scalable solution.

Yes that is correct. The code works well for two nearby trigger boxes, but when there are multiple trigger boxes and can be approached from different angles, it leads to each trigger needing multiple checks for every voice over in the immediate area.

Create an actor that manages all the audio. Have the triggers just tell said actor what to play.

I would do as @pezzott1 suggested and have an actor manage your audio, however, this works in the level blueprint.

As an after thought you should also have a check for if the array length is 0 to avoid any unnecessary looping/potential bugs. I’d add this at the start of the custom event before the check for IsTimerActiveByHandle.

You’ll need to create a few variables, most of which are self explanatory.
For the Sound Queue variable I created an array variable of type Sound Cue.

1 Like

Why not simply setup a concurrency setting?

Sounds → Sound Concurrency

  • max count: 1
  • rule: stop oldest

Apply concurrency to the sound cue directly (details), or to the play node.


Thank you so much, this worked like a charm.
For the afterthought, I added a length check for the Sound Queue, after the PlaySound custom event. If the value’s greater than zero, it continues through the branch. If it’s zero, the Sound Queue is cleared of all content. Hopefully that does the trick.