+7 votes

I have flashing text that show the player which buttons they use for there paddles.
Once the flashing is done I want to delete the node altogether. When I run queue_free() or remove_child() I can still see the node in the inspector.

What am I missing? Here is the code. I know I make it into that block of code because in the inspector I can see that the hide() function has worked.

elif flash_opacity < 0:
    flash_times -= 1
    if flash_times == 0: # The number of times to flash has ended so kill the node
        flash_player_buttons = false
        hide()
        get_tree().queue_free()
        get_tree().remove_child(self)
    flash_up = true
in Engine by (78 points)

2 Answers

+9 votes
Best answer

It's not get_tree().remove_child(self). It'sget_parent().remove_child(self)

I found that queue_free() also works.

On a side note it also tried get_parent().queue_free() and that just deletes everything in your parent node. For me that was everything on the screen.

My new code now looks like this:

elif flash_opacity < 0:
    flash_times -= 1
    if flash_times == 0: # The number of times to flash has ended so kill the node
        flash_player_buttons = false
        hide()
        # get_parent().remove_child(self) # this also works
        queue_free()
    flash_up = true
by (78 points)

Use just free() for nodes that are not on the tree (in case you have one).

+13 votes

queue_free is the safe standard way to destroy a node, and must be called on the node, not on the scene tree (because destroying the scene tree will destroy everything).

by (28,795 points)
edited 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 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.