Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Audio.Play() and the annoying problem with delay

Discussion in 'Audio & Video' started by delibowlen, Apr 14, 2015.

  1. delibowlen

    delibowlen

    Joined:
    Jan 16, 2013
    Posts:
    57
    I´m building an asset and this needs a play delay about several SAMPLES. Now UNITY is giving me that annoying message in the console:
    "Delayed playback via the optional argument of Play is deprecated. Use PlayDelayed instead!" but in PlayDelayed I can only use seconds because:

    "This is inconvenient when the engine is running on a different sample rate and the source sound has an even different rate. Working with delays specified in seconds makes this independent of these."

    For what I´m building the point about the sample rate is unimportant to me and I NEED to delay it via samples because many tests showed me that a delay via seconds is very very inaccurate for my purposes.

    So how can I avoid this "error" message? Is there even a way to avoid it? What is the UNITY TEAM planning about this? Will it be unavailable in the future so my whole project is dead birth right now?
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    I'm curious - as always - why is a delay in seconds "very very inaccurate" for you?
     
  3. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Use PlayScheduled instead. PlayDelayed can't be more accurate than frame rate, hence your trouble... One way to phrase the issue with PlayDelayed is "PlayDelayed, but from which reference time?" That reference time can't be a stable tick, since it's the time at which you call the method from the main loop, i.e. framerate dependent.
     
  4. delibowlen

    delibowlen

    Joined:
    Jan 16, 2013
    Posts:
    57
    Thank you gregzo, it works fine with PlayScheduled(). No cracks or other sound "mutations" at the begin and the end of the sounds...