Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Sounds getting cuttoff with AudioSource.Play()

Discussion in 'Audio & Video' started by ninjapretzel, Apr 22, 2015.

  1. ninjapretzel

    ninjapretzel

    Joined:
    Jul 19, 2011
    Posts:
    27
    The gun sounds in this video are being played by AudioSource.Play()
    They are one-shot sound objects created in code when the gun fires.

    I instantiate a game object with the AudioSource attached and set up, and then assign the sound (loaded dynamically via resources, in the video, these are all already loaded) to the AudioSource's clip field, and then call the Play() function of the AudioSource.

    Sometimes, the begining of the sound is cut off when it is played. It's often enough that it doesn't sound right.
     
    JoRouss likes this.
  2. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    164
    From where in your code are you calling Play() on the AudioSource?
     
  3. ninjapretzel

    ninjapretzel

    Joined:
    Jul 19, 2011
    Posts:
    27
    When the audio source is created.
    basically it's something like:


    AudioSource source = Instantiate(settings, pos, Quaternion.identity) as AudioSource;
    source.clip = sc;
    source.volume = Settings.soundVolume;
    source.Play();
     
  4. Lukas-Wendt

    Lukas-Wendt

    Joined:
    Jun 1, 2014
    Posts:
    13
    unitybru likes this.
  5. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
  6. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    217
    Still getting this problem in Unity 2019.4 LTS. I'm starting the sound in a MEC Coroutine. Not sure if that is the reason.

    Edit: Changing the priority to 0 seems to have fixed the issue.
     
    Last edited: Jun 11, 2020
    harlandpj likes this.
  7. harlandpj

    harlandpj

    Joined:
    Jul 15, 2020
    Posts:
    6
    Interesting, will try that myself, I have tried every variation of Play(), PlayOneShot() with a Coroutine to delay anything else happening soundwise, used WaitForSeconds(clip.length), even added a little onto the delay time to see if it stops, and guess what... no luck so far. Will try changing priority and hope that works (first i've heard of it lol)!
     
  8. JohannaJacob

    JohannaJacob

    Joined:
    Jul 23, 2013
    Posts:
    3
    I also have the problem in Unity 2019.4 LTS. For some strange reason, AudioSource.PlayClipAtPoint works.
    I don't think starting the sound from a coroutine is the issue, because starting it from anywhere in the script causes issues, as well as the standard "play on awake" checkbox in the Audioclip itself.

    Changing the priority to 0 did not fix the issue in my case. Really annoying, but at least AudioSource.PlayClipAtPoint works.
     
  9. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    217
    Switched my audio solution to FMOD a while back and could never go back to using Unity's default audio solution. If you have a day to spare to learn how to use it, I highly recommend making the switch. It's free (for small devs) if you haven't heard of it before. Haven't had one problem with audio since.