0 votes

Hi everyone,

Instancing Scenes in the docs (https://docs.godotengine.org/en/latest/tutorials/scripting/nodes_and_scene_instances.html) leave me a bit paranoid with one open question, because I read a lot about Node.queue_free and remove_child(node) and alike. I believe I can relaxe on this one but I'd like confirmation from the experts once and for all *: )*

My case: I have prepared a simple animation-scene (a circle expanding and fading out) that is put on top of any button withing my project when pressed.

func _on_Button_gui_input(event):
    if event.is_action_pressed("mousebuttonclick"):
        var buttonpresscircle = preload("res://button-press-circle-scenes/ButtonPressCircle.tscn").instance()

This works great. Every button features that code.
I don't have to „remove“ anything after that little animation is being „called“, do I? It's not „adding up garbage“ anyhow when pressing more and more buttons over time, right? Or should I somehow „delete“ the scene again right after it's finished the animation?

Godot version 3.3
in Engine by (492 points)

1 Answer

+1 vote
Best answer

Each time you will press the button will add that animated scene. And soon you will discover that these are actually accumulating. To see it run your project press that button a few times. Then minimise that game window. Now in the inspector click on the remote button. Now just see there are many more nodes of the animation scene. Better if you delete all the animation node after the animation is finished either by queue_free()or by remove_child(node)

by (942 points)
selected by

Yes, I can indded see them piling up in the remote scene tree.
Originally I didn't even have a script attached to the instanced scene as the animation runs on startup one shot. Now I added a

func _ready():
    yield (get_node("ButtonPressCircleAnimPlayer"), "animation_finished")

and the Node is being deleted.

Thanks for your help!

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.