T
Tyberiusz

How Godot works?

"The queue_free() function

Every node in Godot comes with a member function named queue_free(). Calling it asks the engine to mark the node for deletion and delete it as soon as possible.

Godot keeps a queue of these nodes in an array and deletes as many as it can at the end of each frame."

Does it mean, that Godot goes through game code once a frame, but executing the code may last longer; so when going through code next frame,  orders from previous frames may not be executed yet?

If so, objects may exists in spite of the order to delete them in previus frame and  program (in next frame) will interact with these objects that should not exist anymore?

So if my computer would play the game 1 fps; the already killed enemy would be alive a second longer, able to fire his gun?

  • Nathan Lovato replied

    I think we need to tweak this explanation. queue_free() asks Godot to delete the node at the end of the frame. It's a safe way to delete nodes, as there may still be nodes or functions trying to use these nodes this frame.

    That aside, it doesn't have other side effects where code would get executed with a delay, for instance. It's just, the node will get deleted at the end of the current frame instead of immediately. There's a complementary free() function that frees a node immediately, without waiting for the end of the frame, but we almost never use it as it tends to cause bugs.

    1 love