How to play a singular sound that's triggered by a multi sphere trace by channel.

Hi! I have a system where I am making a sphere trace that can target multiple enemies, and it plays a specific sound depending on if an enemy has been hit or if nothing has been detected. However, for example, if the trace detects 3 enemies, it will play the sound 3 times. I tried using a doOnce node, but this still played the audio for however many objects are included in the sphere trace.

I’m also detecting whether the hit targets implement a specific interface, so that when the sphere trace happens and no enemies are detected, it plays a “fail” sound. However, as its also picking up on static meshes in the scene, it plays that fail sound for however many static meshes are included in that sphere trace.

Is there a way I can make it just play once? So for example, if the sphere trace happens and there are 3 enemies, it will recognize that the hit is successful and play the audio once instead of stacking 3 on top of each other.

Here’s what the blueprint looks like. I’m doing this on the main character blueprint. There’s probably a more efficient way for me to do this, I’m still learning so any ways of improving it would be appreciated :slight_smile:

TLDR; I’d like to have one sound play depending on if something is hit or not, instead of the audio stacking depending how many targets are included in the hit.

The reason why the sounds are playing for every collision is because you literally have a loop that is running for every collision of the trace.

So if the trace hits 10 things, that loop will run 10 times, the only thing that needs to be satisfied is that one Boolean. So its running multiple times because of that.

Instead, take the code for checking with the Boolean and playing the sound code, and move it to the completed exec pin on the loop.

your code should probably instead look something like this.
For (hitTraceArray):
if current hitTrace struct in array has valid hit;
set containsHit to True;

(then on the completed node)
if containsHit is True
play sound;
if not, play other sound;

(Let me know if that helps)