Queue_Free is not deleting scene from root

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By connortbot
#Adds an instance of the Main GUI under Lobby
get_tree().get_root().get_child(5).queue_free() #kills lobby menu
get_tree().get_root().add_child(main_scene.instance())
client = get_tree().get_root().get_child(3).get_child(1)
if Database.LOCAL_ID == 0:
	if new:
		emit_signal("start_game_org")
	else:
		emit_signal("start_loaded_game")

This is the code for my “start_loading_game” function. I have run it with print messages around the “queue_free” line and it prints out 5 children, with the “StartMenu” being the 5th. However, the prints show that the line does absolutely nothing.

The function itself does not error out. However, after the “start_game_org” signal is sent another function tries to trigger another function in the 5th child of root - which for some reason is still StartMenu. It should be the main_scene instance, which would be the 5th one after StartMenu is freed.

What are the possible reasons this could be happening?

:bust_in_silhouette: Reply From: Inces

Perhaps another function uses a reference to 5th child taken in onready setting.
This would still lead to startmenu, even when it was deleted after ready function

I checked, I do not think this is an issue. There isn’t any other running function that references the StartMenu tscn file.
What counts as a reference for this?

Also, why would this affect it? I watched the remote panel to look at the root children and didn’t even see StartMenu go away, so it must’ve never been deleted.

connortbot | 2022-08-18 21:14

What else do you think it could be?

connortbot | 2022-08-18 21:16

You will just have to print every other line to understand what happens. Perhaps there is menu created another time by code, doubling with the one from editor. Or something.
so print 5th child
queue free 5th child
print 5th child again

do the same prints in another function, thatn referes to 5th child later on

Inces | 2022-08-19 09:21

To the 5th child or to StartMenu?
This is the problem, there are no other references to the StartMenu until after a full game is finished, and they do not run.

I did what you suggested with the prints. It prints StartMenu before and after, as if the queue_free is ineffective.

connortbot | 2022-08-20 14:12

and it prints the same ID of a node ?
This sounds ridicolous :slight_smile:
You don’t have any code in menu _exit_tree, do You ?
Or does menu has something very dense in its process() ? Like yield ?
if no, well, time to try it with free() function

Inces | 2022-08-20 15:20