0 votes

My node can shoot bullets, which are added to it as children. When the node dies I do not want all its bullets to die. I have a function that calls remove_child and add_child on all the bullets, removing them from the parent and adding them to '/root'. Something like this:

func kill_entity:
    remove_all_bullets_and_add_to_world() #works fine according to remote inspector
    queue_free() #still deletes the bullets!

I have seen that this works in the remote inspector, a breakpoint after doing this shows the bullet nodes are on the root object. However, calling queue_free afterwards still deletes all the bullets as if they were still children. They are removed from the screen and from the remote inspector (so they're not just being repositioned). Any ideas why this might be?

in Engine by (654 points)
edited by

I'd have to take a look at your project, if you could upload it. However, what you're trying to do smells a bit like bad architecture. Why not gathering the bullets in a seperate container in the first place? You can set their positions easily like this from any node:

var gun = get_node("../../Gun")
var bullet = get_node("../BulletContainer").get_child(0)
bullet.global_position = gun.global_position

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.

Categories