Audio Looping in Unreal Engine 5 and Pause/Play
In Unreal, when my player takes 75% damage, an associated sound plays. However, I have certain crystals that restore health, such as this one , and when the player touches them, the sound obviously shouldn't play anymore, as that sound should only play when the player has 25% health remaining (i.e., they've lost 75%).
Problems Using "Spawn Sound 2D" with Looping
To play sounds in a loop, since this is a sound that repeats continuously, we can import the sound, check the Looping option, and in principle, we could use the node called Spawn Sound 2D, which has methods to start or stop the audio:

The problem is that when the sound is already defined as looping, it can't always be stopped correctly; it almost never worked for me. For example, when I tapped the glass to give it more life, I wanted to stop the heartbeat sound that had been heard before, but it wasn't possible.
Solution: Use an Audio Component
Since the previous solution doesn't work when trying to stop looping, what I did was the following:
Simply, for the player, I added an audio component. Search for "Audio" and add it; in my case, it's exactly the one you're seeing on screen.
Then, assign the audio you want to play, which in my case is the one you heard, and activate the Looping option. By the way, it sounds like this.
Instead of using the node that didn't work (Spawn Sound 2D), what you do is simply reference the audio component: drag it, then call the Play method when you want to play the audio, and the Stop method when you want to stop it.

Important Detail: Disable Auto-Active
Also, remember to disable the Auto-Active option so that it doesn't start automatically when the game starts. In my case, that's exactly what I wanted, as I only want the audio to start programmatically when the player takes damage.
I agree to receive announcements of interest about this Blog.
We'll see how we can implement a looping audio system that we can pause and restart at will.
- Andrés Cruz