0 votes

Script is spawning bullets inside enemy and use setastoplevel(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?

Godot version 3.5.1
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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

by (336 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.