In godot 4.0.2, I am using get_tree().change_scene_to_file("res://level_2.tscn") and it is saying that the scene does not exist. I cheked and it does, I also draged the scenes name directly from the file manager, and it didnt work. Wierd thing is I am calling the exact same line of code in a different script, and it works there. I tried the same thing with get_tree().change_scene_to_packed(load("res://level_2.tscn")) and it doesn't work aswell. Mysterious bahavior. I am sure the file exists and I copied the name correctly. Note I am passing in an exported variable to the function.
What could the problem be ? Also how do you export variable with the file selection popup like you could do export(FILE, String) in Godot ?

You have double quotes on the string. Try this:

get_tree().change_scene_to_file("res://level_2.tscn")

    cybereality I did it by using export_file and now I am getting a new error : drivers/windows/file_access_windows.cpp:123 - Case mismatch opening requested file 'level_2.tscn"', stored as 'level_2.tscn' in the filesystem. This file will not open when exported to other case-sensitive platforms. Please help me.

    7 months later

    I have a problem with change_scene_to_file() too. Here is my code:

    	get_tree().change_scene_to_file(level_path)
    
    	var fish_player = load("res://Assets/Characters/FishPlayer.tscn")
    	var player_inst = fish_player.instantiate()
    	get_tree().current_scene.add_child(player_inst)

    Here is my error log:

    Cannot call method 'add_child' on a null value.

    It seems a newly changed scene isn't loaded yet. I run this code from my GameManager singleton.

    • xyz replied to this.

      Mifth change_scene_to_file() is deferred. It will be executed after the current frame has finished processing. You can try await get_tree().process_frame before accessing the current_scene property.