How to play a one shot audio sample in godot 3?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By talador

If I set the AudioStream2D playing equal to true in the _ready function it plays fine, but if I do the same thing on a Area2D “body_entered” callback, it won’t play the audio. I’m trying to just play a sound when an item is touched

is body_entered even called?

Zylann | 2018-08-17 17:39

Yes, the breakpoint hits inside the function and it doesn’t fuss about $AudioStream2D.play() or $AudioStream2D.playing = true, it calls it but maybe 1 in 100 times I hear the first little blip of the sound. (looping is disabled)

talador | 2018-08-17 18:24

Did you try calling play()?

Zylann | 2018-08-17 22:06

Yes, it doesn’t seem to work properly from within body_entered, it will rarely play a small part of the sample, but not every time

talador | 2018-08-17 23:14

The sound not playing is just weird… I don’t think it’s directly related to body_enter, something else might be happening. Do you have a simple project showing this bug?

Zylann | 2018-08-18 00:15

I made the simplest project I could using the Area2D method for playing a sound and it worked fine… I’m looking over my other project to see what is different.

edit: I was freeing the object that’s why it wouldn’t play… silly me.

talador | 2018-08-19 02:53