Change_scene_to_packed() does not call ready() on previously loaded scene

Godot Version

4.2.2

Question

The starting flow of the game is this: players are given a title scene, then a level selection scene, with the button for the first level focused (the button’s grab_focus() function is called in that scene’s _ready() function). When a level is selected, play begins in that level.

If a player presses the Menu button on the controller, they are sent back to the level selection scene. However, for some reason the ready() function is not called this time, so no button is assigned focus, and no one can select any level at this point.

I’m using change_scene_to_packed() to move from one scene to the other. The documentation leads me to believe that scenes are fully torn down when moving away from them, so why wouldn’t ready() be called? Or what can I do differently?


const CHOOSE_LEVEL_SCENE : PackedScene = preload("res://Scenes/choose_level_screen.tscn")


func show_choose_level_scene():
	get_tree().change_scene_to_packed(CHOOSE_LEVEL_SCENE)

It removes the sub scene, it doesn’t add a new scene as child. So if the main scene is already loaded into the tree it will not call ready again. Ready is part of being added to the scene tree.

I follow what you mean, but when I print(get_tree_string_pretty()) in the game level, the choose level screen is not part of it. Using “change_scene_to_packed()” to go from scene A to B to A, does not seem to leave scene A in the tree when scene is changed to B.

add
_enter_tree():request_ready()

1 Like

@solver10
Oh interesting, I did not know that ready is a one time thing. I thought it would call it each time you add it as a child.

I do not like to remove nodes from scene tree, just make them freed and instantiate new. Because it solves many bugs similar to TS