How to change scenes in Godot 4: change_scene_to_file()
By Eduardo Orellana · Updated
Call get_tree().change_scene_to_file("res://level_2.tscn") to load a scene from its path and make it the current scene, or change_scene_to_packed() with a PackedScene you already loaded. The Godot 3 call get_tree().change_scene(...) no longer exists and stops with Invalid call. Nonexistent function 'change_scene' in base 'SceneTree'.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
Godot 4 split the call by what you pass: change_scene_to_file(path) loads the file, and change_scene_to_packed(scene) takes a PackedScene. Godot 3's change_scene() and change_scene_to() are gone, so the call fails on SceneTree.
The change is deferred: the current scene is freed and the new one added at the end of the frame, so code after the call still runs on the old scene. The new scene is get_tree().current_scene from the next frame.
Reproduce it
A Godot 3 scene change, in a Godot 4 project.
extends Node
func _ready():
get_tree().change_scene("res://level_2.tscn")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Invalid call. Nonexistent function 'change_scene' in base 'SceneTree'.
at: _ready (res://answers/how-to-change-scenes-in-godot-4/repro.gd:4)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/how-to-change-scenes-in-godot-4/repro.gd:4)Fix it
change_scene_to_packed() with a level packed in code, so the run needs no second file; change_scene_to_file() works the same from a path. The new level prints its name from its own _ready(), because this script is freed with the old scene.
extends Node
const LEVEL_SCRIPT := "extends Node\nfunc _ready():\n\tprint(\"current scene: \", get_tree().current_scene.name)\n"
func _ready() -> void:
var script := GDScript.new()
script.source_code = LEVEL_SCRIPT
script.reload()
var level := Node.new()
level.name = "Level2"
level.set_script(script)
var packed := PackedScene.new()
packed.pack(level)
level.free()
print("leaving ", name)
get_tree().change_scene_to_packed.call_deferred(packed)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
leaving Fix
current scene: Level2Changing scene from _ready()
Calling change_scene_to_file() or change_scene_to_packed() straight from the current scene's _ready() prints Parent node is busy adding/removing children, `remove_child()` can't be called at this time, because the tree is still adding that scene. Defer the call with call_deferred(), as the fix does, or wait a frame first.
Keeping data between scenes
Changing scene frees every node in the old one. Keep score, inventory or settings in an autoload (Project Settings, Globals), which survives the change.
Verified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [gdscript_vm.cpp line 163, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L163), [SceneTree.change_scene_to_file and change_scene_to_packed in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/SceneTree.xml).
Questions
- Why does code after change_scene_to_file() still run?
- The change happens at the end of the frame. The rest of the function runs first, still in the old scene.
- How do I reload the current scene?
- get_tree().reload_current_scene().
Related
- Invalid call. Nonexistent function 'instance' in base 'PackedScene'
- Preload file "…" does not exist
- Every verified Godot 4 answer
- Parent node is busy setting up children, `add_child()` failed in Godot 4
- Cannot call method '…' on a previously freed instance in Godot 4
- Trying to cast a freed object in Godot 4
- Invalid call. Nonexistent function '…' in base 'Nil' in Godot 4
- Cannot call method '…' on a null value in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free