#Playing destroy-sound before queue_free

7 messages · Page 1 of 1 (latest)

icy ledge
#

Heyho! Still inexperienced with Godot.

I have a Meteor-Scene (Area2D) with a Sprite, Collision and a AudioStream2D.
The stream contains a sound effect that is supposed to be played when the meteor is destroyed by a projectile.
But playing that sound right before calling "queue_free" destroys the stream-node aswell, causing the sound to not be played.

Is the only way to seperate the audio logic into a Singleton with signals?
I would have liked to keep it in the Meteor-Scene if possible

#
func _on_area_entered(area):
    if(area.is_in_group("projectiles")):
        breakSound.play()
        split() // Spawns more (smaller) meteors
        self.queue_free() // Destroy self
        area.queue_free() // Destroy the projectile
cursive pebble
#

A common thing to do, if you don't want an autoload, is to make its visible value equals to false instead of queue free, and after the sounds ends playing, you queue free it

icy ledge
#

Mh ... not sure I like hiding the node. That would add the need for a lot of additional logic and edge cases.
Thanks for the heads-up! If this is the only alternative I'll make seperate audio-node instead.

cursive pebble
#

It is a good idea. I use the autoload method for sounds and works wonders. Really simple to implement too

rotund hinge
#

To add to ZeroVoltios comment about changing the sprites visibility, to avoid all of the logic and edge cases, disable its collision shape as well. This will effectively destroy the node, since it wont be able to interact with anything. after that, just await the audio's finished signal and then call queue free there.

#

Game dev is A LOT of smoke and mirrors, so dont feel like there is ever just ONE way to do something.