Godot Version
v4.2.1.stable.flathub [b09f793f5]
Question
Brand new Godot project, I have two scenes main.tscn
and menus/login.tscn
.
main.tscn
is the main scene, has a Control node as root and the following script attached.
extends Control
func _ready() -> void:
# TODO: If not GameLauncher provided user ID, or locally stored ID.
if true:
get_tree().change_scene_to_file("res://menus/login.tscn")
When I run it changes the scene but logs the following error:
E 0:00:00:0421 main.gd:8 @ _ready(): Parent node is busy adding/removing children, `remove_child()` can't be called at this time. Consider using `remove_child.call_deferred(child)` instead.
<C++ Error> Condition "data.blocked > 0" is true.
<C++ Source> scene/main/node.cpp:1436 @ remove_child()
<Stack Trace> main.gd:8 @ _ready()
I found change_scene_to_file
in the docs.
How am I supposed to change a scene in Godot 4?