Playing a sound and dropping particles after a monster's death

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Kaendan
:warning: Old Version Published before Godot 3 was released.

Hello guys!

My friend and I are trying to create a top-down adventure game.
In our game, when we kill a monster, it drops some particles and a sound is played. Here is our problem: How can we destroy our monster and not destroy its particle and soundplayer node?


We found two solutions but we are not sure which one we should use and if they are really good :

  • At the beginning I simply created a deathtimer:
    When a monster die, I queue_free() its sprite, its CollisionBox and everything that could create any bug. Then I start the timer, play the sound and drop the particles. At the end of the timer, I queue_free() the entire scene.
    The problem with that solution is that, appart from particles and the soundplayer, I have to queue_free() everything inside my monster scene to avoid any bug (remaining collisions for example). I don’t really thing this timer trick is a good solution.

  • Then I thought that a better solution would have been to reparent the particle node and the soundplayer so that they can still live in the world scene without the monster. With this solution I can queue_free() my monster without any problem. BUT! Particles in the world scene are never destroyed! What should I do? Create a “temporary_object” script to destroy particles and soundplayer on_finished?
    With that solution, I don’t have to worry about using queue_free() on a lot of nodes inside my monster scene. But I still have to reparent what I want to keep and maybe create some temporary objects. So is that finally a better solution ? I’m not sure about it…


How would you do that?

I really hope this post is understandable.
Please ask questions if you want some clarification!
Thank you for you reading and/or your help!

:bust_in_silhouette: Reply From: Zylann

The solutions you found are not too bad. I had the same issue in my game with exploding elements.
If it’s possible, I would separate the “explosion” as another scene, and instance it before removing the monster as child of the parent of the monster. The advantage of this is that you get a modular design, and you don’t need to partially queue_free() any scene :slight_smile:
Also, since it’s an explosion, it should be removed afterward, so like you said I would have a script that destroys the object after a short time.

Thank you for your answer! Yes that’s a good idea! I thought about it but I was not sure if it was the way to do that since it would have made a lot more scenes in my game. Actually, I want to have different death animations for each monster in the futur. Particles are probably a temporary solution. Maybe using Timers will be a better solution when I’ll implement death animations.

Kaendan | 2016-07-15 10:31