Skip to content

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.

Download for macOSDownload for WindowsDownload for Linux

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.

More on this: How to tween in Godot 4: create_tween() and tween_property()

Reproduce it

A Godot 3 scene change, in a Godot 4 project.

GDScript
extends Node

func _ready():
	get_tree().change_scene("res://level_2.tscn")

What Godot 4.7.2 prints

Output
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.

More on this: Left operand of 'is' is a previously freed instance in Godot 4

GDScript
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

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

leaving Fix
current scene: Level2

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

More on this: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead in Godot 4

Prompt
How to change scenes in Godot 4: change_scene_to_file() 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'. Where this calls for a change in my Godot 4 project, make it, then run the game headless and check Godot's output for errors.

Changing 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.

More on this: Parent node is busy setting up children, `add_child()` failed in Godot 4

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, SceneTree.change_scene_to_file and change_scene_to_packed in the class reference.

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().

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free