7
\$\begingroup\$

For Unity AudioSource objects, what is the difference between the Play and PlayOneShot methods, besides their method signatures?

Is it simply that PlayOneShot won't stop an already playing sound from the AudioSource? So given a scenario where you can guarantee that a call to AudioSource.Play() won't occur again until its isPlaying boolean value is false, is there any reason to use PlayOneShot?

\$\endgroup\$
  • \$\begingroup\$ Yeah it's weird that even 2 years later, the Unity documentation still doesn't mention this! \$\endgroup\$ – Kokodoko Feb 16 '18 at 20:29
5
\$\begingroup\$

You've already identified the main difference: PlayOneShot can play multiple sounds without cutting each other off. On the flipside however that means* you can't stop the audio clip either; it'll just play all the way through, with no way to stop it early.

*I think; I can't test this at the moment, but I recall that calling Stop() after PlayOneShot() does nothing.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Just updating on @jhocking s answer. calling Stop() will stop the current clip, even if it's played using PlayOneShot() \$\endgroup\$ – Sidharth V Sep 2 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.