This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

My UI adds buttons programmatically, and then attempts to unload them via queue_free() before adding new ones. Problem is, they don't unload in time to prevent the UI from breaking in an attempt to fit all the buttons (old, invisible, queued-for-deletion buttons and new ones).

The below solves the issue by essentially waiting out the frame, but is definitely not ideal:

yield(get_tree().create_timer(0.001), "timeout")

Is there a way to essentially wait until the next frame tick happens instead?

Godot version 3.2.3
in Engine by (26 points)

3 Answers

+4 votes
Best answer

The literal answer to your question is yield(get_tree(), "idle_frame") (SceneTree emits idle_frame "immediately before Node._process is called on every node in the SceneTree." (https://docs.godotengine.org/en/latest/classes/class_scenetree.html). But I strongly suspect the suggestion of just doing remove_child before queue_free is better.

by (60 points)
selected by

Thanks, this is what I needed!

I had read in other places that remove_child didn't have much value over queue_free, and I mistakenly took that at face value. In my case both are definitely needed.

Chose this as best answer because it also explains how to wait a frame as well, if I ever end up needing that.

0 votes

Have you thought sending a signal on button unload? The callback function for the signal would load new button.

by (28 points)
+3 votes

If I understand your question correctly, you can use remove_child to remove your buttons from your Tree, and thereafter use queue_free to tell the engine to remove them completely when possible

by (127 points)
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.