I fixed this, for some reason my sound manager had wrong names for things and it played sounds along with the objects it spawned to play sounds.
When a sound effect in my game plays multiple times very close together (~0.1 seconds apart) or at once in my game, it will sometimes start to play on top of every sound effect. When it starts doing this, it will happen to every sound effect no matter what. The original sound will play too, but the sound on top of it is often too loud to hear the original. One time it stopped doing this for some reason after I moved around, but I couldn’t recreate this and I have no idea why it happened.
This is my code for the sound manager. It spawns an object to play a sound and then destroys it, meaning it is capable of playing multiple sounds simultaneously. I’ve tried turning off the destruction while debugging and it did nothing.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour {
public AudioClip PlayerJump, Dash, PlayerHit, PlayerMeleeHit, PlayerMelee, PlayerShoot, Parry, ParriedBulletHit, ParriedBulletDeath, BulletCollision, PlayerExplosion, PlayerFireWave, PlayerHeal, PlayerDeath, EnemyDeath1, EnemyDeath2, EnemyDeath3, CommonCollectible, UncommonCollectible, CharmFound, StyleRankUp, PrimarySwap, Pause, Unpause, Menu1, Menu2;
static AudioSource audioSource;
void Start() {
audioSource = GetComponent<AudioSource>();
}
public void PlayClip(AudioClip audioClip, Transform transformToSpawnAt, float volume) {
Debug.Log(audioClip.name);
AudioSource SFXaudioSource = Instantiate(audioSource, transformToSpawnAt.position, Quaternion.identity);
audioSource.clip = audioClip;
audioSource.volume = volume;
audioSource.Play();
SFXaudioSource.name = audioClip.name;
float clipLength = audioSource.clip.length;
Destroy(audioSource.gameObject, clipLength);
}
}
When I Debug.Log the AudioClip’s name, it only ever logs the name of the original sound and not the sound on top of it.
If it’s helpful somehow, I used this tutorial for the sound manager and the code is unchanged except for the sound object getting renamed to the sound it plays: