Sound stops playing when firing a weapon very fast

Hi,
I have an assault rifle, and when I fire it, I’m also playing a sound:

// Try and play the sound if specified. FireSound is USoundBase
		if (FireSound != nullptr)
		{
			UGameplayStatics::PlaySoundAtLocation(this, FireSound, Character->GetActorLocation());
		}

My problem is that when I stay in one place, after aroound 15 bullets some shoots fire without sound. But when I’m moving, I don’t have that problem. I suspect it has something to do with spawning location, but I’m not sure what to do. Could someone help me?

I’d suggest making the sound as the weapon component instead. This way you won’t be spawning dozens of sounds in the short span of time and will only have one component to work with.

Sorry for replying so late. The thing is that it is a part of TP_Weapon component. FireSound is set in blueprints:

image

And How could I avoid spawning dozens of sounds? For every shot, I need to spawn a sound. I was thinking about spawning just one, long fire sound, but then I would need 30 differend soud files with different lengths and I would need to find a way how to determine which one of them I should spawn.

And that sound couse is there because of me testing whether using it will change anything. Sound waves are producing the same bug.

Ok, so I actually managed to resolve my own problem:

// Try and play the sound if specified. FireSound is USoundBase
		if (FireSound != nullptr)
		{
			if (SpawnedFireSound != nullptr)
			{
				SpawnedFireSound->Deactivate();
			}
			//UGameplayStatics::PlaySoundAtLocation(this, FireSound, Character->GetActorLocation());
			SpawnedFireSound = UGameplayStatics::SpawnSoundAtLocation(this, FireSound, Character->GetActorLocation());
		}

SpawnedFireSoud is UAudioComponent* declared in the header file.

Don’t spawn sound at location, just play the sound component audio.

1 Like