How to fix this error?
When I run current scene (level 1) and go thru a door with get_tree().change_scene_to_file("res://menu.tscn") it takes me to menu. Then click on ‘start’ button with get_tree().change_scene_to_file("res://scenes/level1.tscn")
but at this point then it will crash.
simplify: level1 ->door (in level1 to menu) ->start (in menu to level1) → [CRASH]
whereas, if I start from menu → start (in menu to level1) → door(in level 1 to menu) ->menu → [repeatable]
It would not crash. Can go thru door many times.
Also, how to speed up the change scene, it is slow.
What does the error message say? The time it takes to switch scenes depends on the size of the scenes. You can use background threads and a loading screen to make it more pleasent
I changed it a little, because it suddenly has error, something to do with timer error so I added a Timer node and change from get_tree.create_timer(1) to timer.start(1) and await timer.timeout
Then it cannot read the scene.
Error was Invalid type in function 'change_secen_to_file' in base 'SceneTree'. Cannot convert argument 1 from Object to String
and now have another error: Cannot call method 'change_scene_to_packed' on a null value
here is the code for door:
@onready var timer = $Timer
@onready var main_screen = preload("res://menu.tscn") #changed
func _on_lever_is_active():
#var bodies = get_overlapping_bodies()
#for body in bodies:
#if body.name == "Player":
$AnimationPlayer.play("opening")
timer.start(1)
await timer.timeout
$AnimationPlayer.play("opened")
get_tree().change_scene_to_packed(main_screen) #changed
pass # Replace with function body.
func _on_timer_timeout():
pass # Replace with function body.
and this is for the menu (changed the level 1 → world)
You are also starting to play an animation and immediately trying to change the scene here: not saying it is the cause of your problem (I would do as @herrspaten suggested above) but this is certainly strange.