AudioSource.PlayOneShot with negative pitch won't start new sounds
This is either a bug or there is something I could be doing differently. I have a game that is heavily dependent on environment sound effects that use PlayOneShot(). I allow the player to "rewind time" in this game; while these sound effects have a non-zero play position, I hear them played in reverse if time/pitch is negative. The sound effects I have that use Play() and have looping enabled are also played in reverse correctly.
However, after a few seconds of rewinding time, none of the audio sources using PlayOneShot() will start a new sound effect playthrough. It becomes completely silent instead of being able to play those effects starting from the end, even though the code is definitely replaying everything as it should.
Here's a sample of my code (at least with everything I've tried so far) the moment before audio is supposed to be triggered. ChangePitch() typically happens when the player rewinds but there's no difference if I uncomment that line. I have also tried with/without setting the .time and .timeSamples fields, no difference in behavior.
if (_currentTimeMultiplier < 0 && RefAudioSource.timeSamples <= SamplesFromEndBeforeReset)
{
// set time position manually to make sure one shot plays correctly
RefAudioSource.timeSamples = RefAudioSource.clip.samples - 1;
RefAudioSource.time = RefAudioSource.clip.length;
}
else if (_currentTimeMultiplier > 0 && RefAudioSource.timeSamples > 0 && RefAudioSource.timeSamples >= Math.Max(0, RefAudioSource.clip.samples - 1 - SamplesFromEndBeforeReset))
{
RefAudioSource.timeSamples = 0;
RefAudioSource.time = 0;
}
// make sure pitch is set
//ChangePitch(_currentTimeMultiplier);
RefAudioSource.PlayOneShotIfNotNullActiveAndEnabled(); // don't provide volume; audiosource should have volume scaled already
Your answer
Follow this Question
Related Questions
Found a weird problem about AudioSource.PlayOneShot 2 Answers
Play multiple sounds from one object 1 Answer
maybe audiosource problem 1 Answer
Listening to Sound Card Output 0 Answers
I can't set AudioSource pitch. It said "Value cannot be null" 0 Answers