Scripting: Sound.play() vs Sound.playOneShot()

Hallo @Stefan,

Sound.playOneShot() in the public Scripting API allows you to play a sound at a particular volume, but this could also be achieved by setting the volume for a sound and running the Sound.play() method.

The stated benefits are for “repeating sound effects like rain and foot steps”, but this could be done with Sound.play().

So, is the ease-of-volume-change the main benefit, or does playOneShot() have some kind of super-power that play() doesn’t have?

Many thanks,
Geoff @ TechLeap

1 Like

Hi @techleapnz.

Sound.playOneShot() allows you to play multiple instances of the same sound. If you call .play() on an already playing sound nothing happens unless the sound is done playing. So this is useful sound effects with shorter duration.

Here’s an example space to illustrate the behavior more clearly:

One drawback of Sound.playOneShot() is the “fire and forget” nature of this method. Once a sound is played this way, you can not modify the oneshot sound’s playback (ie. stop it before it finishes or alter its volume).

Hope this helps!

1 Like

Aaahhhh, gotcha - thanks for the clarification! It might be good to add this differentiation to the help docs - I think the key point is that you can play multiple instances at the same time (ie, “simultaneously”).

Many thanks!
Geoff @ TechLeap

1 Like