Why i can't change scene

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

im have this script:

extends Area2D

func _on_body_entered(body):
if body.name == “CharacterBody2D”:
get_tree().change_scene(“res://level2.tscn”)

but when i enter in the flag it just crash and give this error:

Invalid call. Nonexistent function ‘change_scene’ in base ‘SceneTree’.

:bust_in_silhouette: Reply From: jgodfrey

That’s because in Godot 4, the SceneTree object no longer has a change_scene() method. You want change_scene_to_file() instead. See the docs here:

1 Like