Invalid call. Nonexistent function 'change_scene' in base 'SceneTree'.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Teorem

Hello.

First of all I’m very novice, sorry if it’s a dumb question but I have read the doc and searched on google and I can’t understand the problem.

I’m trying to run a very simple script to launch my game scene from my main menu scene :

extends Control

func _on_launch_button_pressed():
     get_tree().change_scene("res://Scenes/Game.tscn")

when I launch my main menu scene and click my launch button, the game closes and I have the following error : Invalid call. Nonexistent function ‘change_scene’ in base ‘SceneTree’.

Do I need to declare the function somewhere else? In an autoload or another script?

1 Like
:bust_in_silhouette: Reply From: jgodfrey

I assume you’re mistakenly looking at the Godot 3.x docs. The SceneTree api has changed a bit for Godot 4. You need this now:

get_tree().change_scene_to_file("res://Scenes/Game.tscn")

Docs here.

And, a docs tip… In the footer of the left-hand Docs panel on the web, there’s a docs version selector. Change that to latest for the Godot 4 docs.

jgodfrey | 2022-12-01 14:48

Thank you for the reply and the advice !

Teorem | 2022-12-03 13:08

2 Likes