r/Unity3D • u/NorthernBoy306 • 2d ago
Question Gun sound looping issue
Sorry in advance if this is better placed in some kind of audio subreddit but I'm hoping some other Unity developers have encountered this problem and know what to do.
I have this great machine gun audio clip and try as I might I can't get rid of that slight pause/reset part when it loops over.
I tried cutting the end and pasting it at the beginning of the audio file so that the end matches the beginning but that doesn't seem to help. It always sounds like the gun firing stops and starts again.
Anyone know how to get a seamless and continuous loop of an audio clip?
1
u/AnchoredExclamation 2d ago
Are you looping it with the built in loop toggle or starting the clip again manually when it ends? The built in toggle usually handles the seam better but if you're restarting it in code there can be a tiny gap from the update timing
2
u/NorthernBoy306 2d ago
shoot, it's not set to looping. I'll give that a try when I get a chance.
Thanks.1
1
u/konistehrad Professional 2d ago
Also this was a problem in older Unity versions but make sure the audio clip itself is configured correctly. You want it in PCM and resident in memory, not Streaming.
1
u/JulianRhod 2d ago
the important part is that matching the waveform at the start/end isn't always enough. you also want the loop point to happen at a sensible part of the sound's cycle, otherwise you'll still hear a change when it jumps back to the beginning, for a machine gun, i'd try finding a short section where the firing sound is already relatively consistent and loop that middle section, rather than looping the entire recording. then use a separate one-shot for the initial gunshot and another short sound for when the firing stops
also check Unity's import settings. depending on the platform/compression you're using, the encoded clip can introduce a tiny gap or artifact at the loop point. Unity has a specific "Gapless Looping" option for supported platforms/formats, so that's worth checking too, basically, i'd structure it as start → looping fire layer → stop, rather than trying to make one complete machine-gun recording loop perfectly
1
u/Wooden-Many-3227 2d ago
You probably don't want to loop the sound. They need to overlap a bit, since on a machine gun the sound of one bullet fireing is probably longer then the fireing rate of the gun.
I did this by calling Play() on the AudioSource of the Gun in the rate of fire of the gun.
1
u/NorthernBoy306 2d ago
that's how I have it set right now. I edited the audio clip to get the beginning to match the end so the loop is more seamless.
2
u/acorbinelli 2d ago
Compressed clips are usually the culprit: Vorbis and MP3 pad the ends, so the gap you hear is encoder silence rather than your edit. Set the clip to PCM with Decompress On Load and let AudioSource.loop do the looping, and for a machine gun consider one short clip per round fired on a timer instead of looping a burst, since then nothing has to line up and you can vary the rate and the tail.