Bullets destroying with enemy

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

Script is spawning bullets inside enemy and use set_as_toplevel(true) in bullet script to deateach them from enemy transform. I have a quere_free() in my enemy script and the problem is it deletes every bullet that was shot by the enemy. How can i delete only enemy without deleting every bullet that it shoot?

:bust_in_silhouette: Reply From: BoxyLlama

This is likely due to the bullets being added as a child of the enemy. Using queue_free will destroy all the children of the node too.

Suggestion 1 :
The option I use, is having a Node in the scene tree specifically for bullets. Add the bullet to this node, instead of the enemy node. That way, when the enemy dies, their bullets live on.

Suggestion 2 :
Toggle the visibility and collision of the enemy for as long as they have bullets. Once all bullets are gone, then use queue_free