Weird Sound Looping When Playing Audio Track

So I am using mostly 3D sound within this application, the nature of the application is based on an adaptive environment. When the user interacts with an object it specifically changes the environment around them and also differing sound effects occur.

However I’m having a problem that when playing an audio track in either 2D or 3D, the sound constantly sounds like its looping the first 1 second of the audio clip and sounds VERY jittery.

Does anyone know the cause of such a problem?

Thanks in advance :slight_smile:

Problem sort of solved…

Had the audio track being played in the update function, therefore it was continuously starting.
However I have an IF condition in the update function and if it’s true play the audiosource, how would I counter the problem of it constantly looping other than using a boolean?.

Maybe check if it isn’t already playing, you get an AudioSource.isPlaying field. So:

if( shouldPlaySound && !source.isPlaying ) source.Play();

Can you put up the code you are using? I have had this issue before, its not looping the sounds it is just triggering the sound every second or so. or you using a PlayOneShot?

I have exactly the same problem and I have solved this problem by adding a bool to tell whether the audio is already being played. When the audio is played, the value of the bool changes so the function will no longer be triggered.

private bool TimeUpAudioIsPlaying;

void Start ()
    {
       TimeUpAudioIsPlaying = false;
    }

void PlayTimeUpAudio()
    {
        if (gameOver == true && TimeUpAudioIsPlaying == false)
        {
            TimeUpAudio.Play();

            TimeUpAudioIsPlaying = true;
        }
    }

Don’t do too much in the update void. I suggest using temporary objects that make use of ienumerator and StartCoroutine. Then deleting that object out of the memory.